π In This Post
Lab Overview
On 30 August I opened a bill I did not expect and asked a simple question: what is running, what is it costing, and did I leave anything behind?
The problem. Answering it took eleven separate lookups across five systems β one for what I was charged, one for who changed what, one for what still existed, one for whether anything had alerted, one for what my infrastructure code believed. None of them talk to each other, and each required me to already know it held the answer. Every number had existed for days: a service billing $9.35 a day for a week, a budget alert fired and ignored, anomaly detection flagging eight cents and missing the sixty-one dollars next to it.
The objective. Build an MCP server that lets a model answer the question without knowing which six APIs to call, in what order, with what filters.
The outcome. It works, it costs $0.13, and writing up its own security model caught a claim about it I had published three times and never checked.
| Difficulty | Intermediate |
| Lab runtime | Not recorded |
| Measured cost | $0.13 β nothing bills while nobody is asking |
| Deployment | Terraform via HCP Terraform with OIDC |
| Full lab guide | GitHub β prerequisites, Terraform, commands, validation, cleanup |
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| AWS Lambda + Function URL | The MCP server itself. No hourly charge, nothing idle to pay for. | Lambda runs code with no server to manage; a function URL gives that function its own HTTPS endpoint directly, with no API Gateway in front and no hourly charge for sitting idle. |
| AWS Cost Explorer API | What the account is spending. The only metered read in the build, at $0.01 per request. | The programmatic way to read your own spend. Unlike most read calls it is metered, at a per-request charge, which is why answers are worth caching. |
| AWS CloudTrail / Config / CloudWatch | The other three read paths: who changed what, what still exists, what alerted. | CloudTrail records who called what, Config records how resources were configured, and CloudWatch holds the metrics and logs. |
| Amazon DynamoDB | Caches Cost Explorer answers so a chatty model does not bill per question. | A managed key-value database with no servers to size. You are billed per read and write rather than per hour. |
| IAM | The actual security model β five statements, read back from the API rather than the console. | AWS's permission system. Every call is signed by a principal, and a policy decides whether that principal may make it. |
MCP, in one sentence: a protocol that lets a model call tools you define, where each tool has a name, a description and a schema β and the model decides when to call it.
A tool description is model input, not documentation. It is not text for humans that the model happens to see; it is the thing the model reads to decide what to do. Anything written there is read on every call.
Architecture and Workflow
- A client signs an HTTPS request with SigV4 and calls the Lambda Function URL.
- Lambda rejects anything unsigned before application code runs β the
Function URL is set to
AWS_IAMauth. - The server exposes four tools, each mapping to exactly one read path into the account.
- Cost questions check the DynamoDB cache first, because Cost Explorer is metered per request and the model decides call frequency.
- A cache miss calls Cost Explorer, returns the answer and writes it back to the cache.
- Everything else β CloudTrail, Config, CloudWatch β is a free read, so it goes straight through.
Design decisions
IAM scoped per tool, not per server. Each statement maps to exactly one tool, so the policy reads as a list of capabilities rather than a permission surface.
A Function URL rather than API Gateway. It removes every idle charge and the entire Cognito surface. It also means an off-the-shelf MCP client speaking plain HTTP cannot connect β it gets a 403 before the protocol starts, because it has no idea how to sign an AWS request. For a personal account where the only caller is me, that trade is obviously right; for a platform team it is the first thing to revisit.
A cache in front of the one metered API. When a model decides how often to call something, a cent per request is an architectural constraint, not a rounding error.
Prerequisites
| Requirement | Detail |
|---|---|
| AWS account | Permission for Lambda, IAM, DynamoDB, CloudWatch; and Cost Explorer enabled |
| Terraform | >= 1.10 |
| An MCP client | One that can SigV4-sign requests β a plain HTTP client will get 403 |
| Region | us-east-1 β Cost Explorer is a global endpoint served here |
Know which reads are metered before you design. Almost every describe/list call in AWS is free. Cost Explorer is $0.01 per request, and each page of results counts. That single fact is why there is a cache in this architecture.
Implementation
One Lambda, one Function URL, one DynamoDB table, one role and one alarm. The lab guide carries the handler and the full Terraform.
week-17-mcp-platform-ops/
|
+-- terraform/
| +-- environments/dev/ HCP backend, OIDC, wires the module
| +-- modules/server/ Lambda, Function URL, DynamoDB cache, IAM role
|
+-- src/ the MCP handler and its four tool definitions
+-- scripts/ signed test calls and cleanup
The role is the security model, and it fits on one screen β four read statements, one cache write, one log write:
Validation and Evidence
The question that started the week is the test: ask it, and check the answer against what the account actually contained.
| Test | Expected | Actual | Status |
|---|---|---|---|
| Unsigned request to the Function URL | Rejected before any code runs | 403 from Lambda | Pass |
| Signed request from an allowed principal | Protocol handshake succeeds | Succeeded | Pass |
| "What did I leave running?" | Matches what exists in the account | Matched | Pass |
| Repeat cost question | Served from cache, no second charge | Cache hit; no additional Cost Explorer request | Pass |
| Role holds no write of any kind | True β as published in three files | False: dynamodb:PutItem on the cache table | Fail β the claim, not the build |
Security and Cost
Security
No write on anything the server reports on. The only write in the role is
dynamodb:PutItem against its own cache table. A model steered by a poisoned tool
description can fill a cache; it cannot change the account. That turns a destruction
risk into a disclosure one.
IAM scoped per tool, not per server, and the cache write scoped to one table ARN rather than DynamoDB generally.
AWS_IAM auth on the Function URL. Every request must be
SigV4-signed by a principal allowed to invoke it; Lambda rejects the rest before application
code runs.
Tool descriptions are treated as model input. They say what the tool answers and what it costs, and nothing else.
Permissions are the security model, not code. It would be easy to claim this server is safe because the code only reads. Code can be changed between reviews; a policy is checked by AWS on every call.
Cost
$0.13 measured, read from Cost Explorer. After teardown, $0.00.
| Item | Rate | This build |
|---|---|---|
| Cost Explorer API | $0.01/request, each page counts | the only metered read |
| Lambda | per request, sub-second calls | effectively free at this volume |
| DynamoDB on-demand | per request | effectively free at this volume |
| CloudWatch alarm | $0.10/alarm/month | $0.10/month |
| Function URL | no hourly charge | $0 idle |
Nothing here bills while nobody is asking β which is the useful shape for a tool you consult occasionally rather than run continuously.
Troubleshooting and Lessons
I published a claim about my own security model that was not true
Problem. Three files β the handler docstring, the Terraform comment and
the README β said the role holds no write action of any kind.
Root cause. I wrote it while designing. It was true of the design in my head,
and I never re-read it against the thing I built. The fourth statement holds
dynamodb:PutItem β a scoped write to the server's own cache, architecturally
fine, but the claim was false.
Resolution. Rendering the policy as a screenshot and reading it. The accurate
claim is narrower and still worth making: there is no write on anything the server reports
on.
Lesson. The fix was not proofreading β it was rendering the
artefact as evidence. Describing a policy lets you describe the policy you meant;
showing it forces the one that exists.
The console would not show the proof
Problem. The IAM console lists a policy name and hides its body, so the
screenshot that would prove the claim did not exist there.
Root cause. Chasing the console was the wrong instinct β the authoritative
copy is the API's.
Resolution. Read the policy back from the API and render that.
Lesson. When the console will not show a thing, ask whether the console is the
right source rather than how to make it cooperate.
One metered API changes the architecture
Problem. A model decides how often to call a tool, and Cost Explorer bills
per request.
Root cause. Almost every AWS read is free, so the instinct is that reads are
free. One is not.
Resolution. A DynamoDB cache in front of the only metered path.
Lesson. Know which reads are metered before you let something else
choose the call frequency.
Cleanup and Key Takeaways
Queue a destroy from HCP, then verify against AWS rather than against the run status. The
script checks Lambda, IAM, DynamoDB, alarms and log groups by name prefix, then does a tag
search for Week=17.
That second check exists because of a specific failure. Week 12's teardown reported success and left two S3 buckets behind β a shell script had created them outside Terraform, so destroy had no idea they existed. A destroy run tells you Terraform removed what it knew about. It tells you nothing about what it never knew.
Key takeaways
- The bottleneck was never the data. Every number I needed already existed; what was missing was a way to ask without knowing which API held the answer.
- Know which reads are metered. When a model decides call frequency, one metered API changes the architecture.
- A tool description is model input, not documentation the model happens to see.
- Permissions are the security model, not code. Code changes between reviews; a policy is enforced on every call.
- Render the artefact instead of describing it. Showing the policy caught a false claim I had written three times and read past twice.
References
- The full lab guide
- Model Context Protocol
- Lambda Function URL authentication
- Cloud Financial Management pricing
- Model Context Protocol specification, 2026-07-28
- What changed in the 2026-07-28 spec
- Bedrock AgentCore pricing
- awslabs/run-model-context-protocol-servers-with-aws-lambda
- CloudWatch pricing
- Amazon VPC pricing
- Amazon Lightsail Pricing
Comments