AWS Builder Center
Weekend Agent Challenge: Cost Sentinel

Weekend Agent Challenge: Cost Sentinel

AWS costs are easy to lose track of, especially when you're juggling multiple services across a learning or side-project account. By the time an unexpected charge shows up on a bill, the anomaly that caused it happened days ago. Cost Sentinel exists to close that gap: it's a watcher agent that checks your AWS spend every single day, without you ever opening the console.

SBG Leader

Vision & What the Agent Does

AWS costs are easy to lose track of, especially when you're juggling multiple services across a learning or side-project account. By the time an unexpected charge shows up on a bill, the anomaly that caused it happened days ago. Cost Sentinel exists to close that gap: it's a watcher agent that checks your AWS spend every single day, without you ever opening the console.
Cost Sentinel is triggered by an Amazon EventBridge Scheduler cron job that fires daily at 3:00 PM EAT, no button click involved. On each run, it pulls the last eight days of AWS cost data from Cost Explorer, broken down by service, and compares yesterday's spend against each service's seven-day rolling average. If any service jumps past a configurable threshold (40% by default), it's flagged as an anomaly.
From there, the agent hands the results to Amazon Bedrock, using the Nova Lite model, to turn raw numbers into a plain-English email. When everything looks normal, it writes a short, reassuring "all clear" note. When it finds a real spike, it writes a structured alert: a risk level, likely root causes per service, concrete fix steps with AWS console paths, and an urgency score, so the email is something you can act on immediately rather than a wall of numbers to interpret yourself. The finished message is delivered straight to my inbox via Amazon SNS. I never have to open anything for it to have already done its job.

How I Built It

I started from a working Cost Explorer to SNS pipeline and layered Bedrock on top so the output would be readable rather than raw JSON. Getting there surfaced three real bugs that shaped the final design.
The first was a Bedrock request format mismatch. My initial code sent requests to Nova using the older prompt and completion structure, but Nova models on Bedrock actually expect a messages and inferenceConfig shape, with the response nested under output.message.content. Because I had solid error handling with a fallback message, the bug didn't crash anything, it just silently produced a generic fallback email every time, which took careful CloudWatch log reading to catch.
The second was a region mismatch. My Lambda was deployed in eu-central-1, but the AWS Cost Explorer API only responds from us-east-1, and Bedrock Nova models are concentrated in us-east-1 and us-west-2. Both clients needed an explicit region pinned regardless of where the Lambda itself lived.
The third was subtler: even after fixing both of the above, my "all clear" emails reported spend as $-0.00. AWS cost data includes negative line items from Free Tier credits and discounts, so a near-zero total like -0.0003 was rounding to a negative-looking zero under Python's string formatting. I wrote a small helper that snaps anything within half a cent of zero to a clean 0.0 before it reaches the logs or the AI prompt.

AWS Services Used

  • Amazon EventBridge Scheduler - daily cron trigger, the "always-on" part of the agent
  • AWS Lambda (Python 3.12) - hosts the agent logic end to end
  • AWS Cost Explorer - source of daily per-service cost data
  • Amazon Bedrock (Nova Lite) - generates the natural-language email
  • Amazon SNS - delivers the finished email
  • Amazon CloudWatch Logs - execution visibility, essential for debugging the three issues above
  • AWS IAM - a scoped execution role limited to Cost Explorer read, Bedrock invoke, SNS publish, and log write permissions
EventBridge Scheduler (daily cron)
│
▼
AWS Lambda (cost-sentinel-ai)
│
├──▶ Cost Explorer - pull daily costs by service
├──▶ Bedrock Nova - generate the email content
└──▶ SNS - deliver the email

What I Learned

Bedrock model families aren't interchangeable at the API level. Nova and Claude expect meaningfully different request and response shapes, and picking the wrong one fails silently rather than loudly if you've built in fallback handling, which is a good reminder that graceful degradation can also hide real bugs if you don't read your logs. I also learned that not every AWS API lives in every region; Cost Explorer specifically only responds from us-east-1 no matter where your compute runs. And I learned that negative zero is a real, user-facing bug, not just a theoretical edge case, worth guarding against explicitly rather than trusting a format string to hide it.

Link to App or Repo

Full source code, README with setup steps, and IAM policy:  https://github.com/stmakori/Weekend-Agent-Challenge-Cost-Sentinel/tree/main 
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article