The Problem
No company context
AI tools write code without knowing your codebase, your specs, your stored procedures, your standards. Generic in, generic out.
Zero audit trail
Nobody knows what changed, by whom, against which spec, at what cost. When something breaks, the log is empty.
Knowledge stays siloed
The senior engineer's head is still the source of truth. The pipeline learns nothing. That person leaves, the knowledge walks out.
Pilot never becomes default
The shiny demo works. Then adoption stalls. The new way of working never replaces the old one.
Why AIDLC?
Faster delivery
Tens of dollars per feature, hours of elapsed time. Not weeks.
Built-in compliance
Every action audited. Every dollar attributed to an issue.
Institutional memory
The pipeline learns. The org's knowledge stops walking out the door.
Faster onboarding
New engineers ramp on a pipeline that already knows the codebase.
A pipeline that improves
Each cycle's retro feeds the next cycle's configuration.
Humans stay in control
Agents propose. Humans approve. Every merge is gated.
Problems
No company context
Zero audit trail
Knowledge stays siloed
Pilot never becomes default
Why AIDLC?
Faster delivery
Built-in compliance
Institutional memory
Faster onboarding
A pipeline that improves
Humans stay in control
OpenTelemetry:
Baked in, not bolted on
Auto-instrumentation of .NET and Java services → ADOT collector sidecars on EKS → AWS X-Ray for distributed tracing → CloudWatch for metrics and logs → custom dashboards and SLO alerting. All traces, metrics, and logs flow through a single OTel pipeline, swap backends without re-instrumenting.
VM → Container replatforming
Move off bare VMs onto EKS with proper orchestration, autoscaling, and workload isolation.
Custom metrics
Business and technical KPIs exported via OTel metrics SDK to CloudWatch and Managed Prometheus.
Structured logging
JSON-structured logs with trace correlation IDs, shipped to CloudWatch Logs Insights.
SLO alerting
Composite alarms and SLO burn-rate alerts wired from day one not as an afterthought.
What changes in your architecture
AWS Landing Zone & multi-account governance
AWS Control Tower
Security baseline
Identity & access
Network architecture
FinOps & cost governance
Compliance as code
Measurable results our clients achieve
60-80%
infrastructure cost reduction vs on-prem VMs
10x
faster deployments via GitOps pipelines
99.9%+
availability through EKS self-healing & multi-AZ
<5 min
MTTR with full OTel trace-to-log correlation
Case Study
Enforcing Per-User Daily Spend Limits on Amazon Bedrock with a Serverless Cost Control Layer
10
Per-user daily USD limits enforced in production in three weeks, with 10 person-days of kloia effort
Key AWS Services
Amazon Bedrock, Amazon CloudWatch Logs Insights, AWS Lambda, Amazon EventBridge, Amazon DynamoDB, AWS IAM, AWS Systems Manager Parameter Store
Client: One of the leading banks in the UAE
Challenge: Unmetered per-user Amazon Bedrock usage, visible only on the monthly bill
Solution: Serverless, out-of-band cost control that prices usage per model and blocks users at a daily USD limit
Situation
The bank's Amazon Bedrock usage was not metered per person.
The bank's developers use Anthropic Claude models on Amazon Bedrock through coding assistants such as Anthropic Claude Code and through automated workloads. One automated loop could spend hundreds of dollars in a day, unnoticed until the monthly bill. Across a team, a few dollars of overspend per user adds up to thousands a month.
The platform and finance teams needed what AWS does not provide out of the box for AWS Identity and Access Management (AWS IAM) users: near real-time spend per user in US dollars, and an automatic stop at a daily budget.
Key contributing factors
- Spend was visible only at the account level, on a monthly bill.
- Opus output costs 5x Haiku output per token, so equal token counts cost very different amounts.
- Prompt caching adds cache write and cache read tokens, each billed at its own rate.
Task
Give every Amazon Bedrock user a daily USD budget that is tracked in near real time and enforced automatically, without touching the request path.
Constraints
- Nothing in the Amazon Bedrock request path.
- No changes to developer tooling, endpoints or authentication.
- Everything managed as code in one AWS account and Region.
- Limits owned by the customer.
- A negligible running cost for the solution itself.
Definition of success (from the Statement of Work)
- Every Amazon Bedrock user has a USD spend record updated at least every 10 minutes.
- Cost is calculated per model from all four token types, the way AWS bills it.
- A user who reaches the limit is blocked within one 10-minute cycle.
- Limits change without a redeployment.
- The customer's engineers run the solution on their own.
Scope
A senior cloud and DevOps engineer and a part-time project manager delivered the work in a fixed 10 person-days. Production go-live came three weeks after kickoff, followed by two weeks of hypercare.
In scope:
- Amazon Bedrock model invocation logging to Amazon CloudWatch Logs
- A cost engine that prices each 10-minute window per model and adds the result to each user's daily total in Amazon DynamoDB
- Enforcement through an IAM Deny group, daily USD limits per user group in AWS Systems Manager Parameter Store, and a daily reset
- HashiCorp Terraform for every resource, a GitHub deployment pipeline, a README and runbooks
- An acceptance framework of 43 controls across nine domains, 18 of them Critical
Out of scope:
- Inline, pre-request enforcement (a proxy, gateway or authorizer)
- Federated identities and assumed roles
- Non-Anthropic models, Amazon Bedrock Agents, Knowledge Bases, Guardrails and provisioned throughput
- Monthly budgets, user notifications, chargeback dashboards, and multi-account or multi-Region rollout
Roles and stakeholders
|
Role |
Party |
Responsibility |
|---|---|---|
|
Senior Cloud / DevOps Engineer |
kloia |
Design, Terraform, cost engine, acceptance and handover |
|
Project Manager |
kloia |
Timeline, session notes, change requests |
|
Platform / Cloud Team |
Client |
Accountable for design and deployment; IAM user naming |
|
Information Security |
Client |
Prompt data in logs; review of the Deny model |
|
FinOps / Finance |
Client |
Daily limit per group; cost reconciliation sign-off |
Action
kloia built two scheduled AWS Lambda functions that do all the work, outside the request path.

Figure 1. Per-user Amazon Bedrock cost control: AWS architecture.
Architecture
Amazon Bedrock logs every invocation with the caller's IAM ARN, model ID and token counts. Every 10 minutes an Amazon EventBridge schedule starts the token checker. It queries the last window with CloudWatch Logs Insights, prices each invocation at its model's rates, and adds each user's delta to a daily total in Amazon DynamoDB. When a total reaches the group limit held in Parameter Store, the user joins the bedrock-disabled IAM group, whose explicit Deny on bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream overrides every Allow.
At 00:00 UTC the daily reset zeroes every counter and empties the Deny group. The user's group comes from the IAM username (Bedrock-{group}-{name}), so a new group is a new parameter, not a code change.
Service selection
|
Service |
Why chosen |
Key alternative considered |
|---|---|---|
|
Amazon CloudWatch Logs Insights |
Reads logs Amazon Bedrock already writes; no request is intercepted |
An inline metering proxy, which adds a hop to every call |
|
AWS Lambda + Amazon EventBridge |
About 4,300 short runs a month, pay per use, nothing to operate |
Always-on compute, which costs more than the problem at this volume |
|
Amazon DynamoDB (on-demand) |
Atomic ADD keeps totals correct across concurrent or retried runs |
A relational store, which needs locking for the same guarantee |
|
AWS IAM explicit Deny group |
One membership blocks a user; removing it restores access |
Editing each user's policies, which is slower and harder to audit |
|
AWS Systems Manager Parameter Store |
Finance changes a limit and the next run applies it |
Limits in code, which need a redeployment |
These choices follow the Cost Optimization and Operational Excellence pillars of the AWS Well-Architected Framework. Because the control is outside the request path, a failure leaves Amazon Bedrock working and users simply uncapped.
Key architectural decisions
- Enforce out of band. Polling adds no latency or availability risk and needs no tooling changes. The trade-off, accepted by the customer: a heavy workload can overshoot within one window.
- Count dollars, not tokens. Budget owners think in dollars, and the same token count costs up to 5x more on Opus than on Haiku.
- Price per model, including cache tokens, so calculated cost follows the shape of the bill.
- Make the block a group membership. Blocking and restoring are single IAM calls, and AWS CloudTrail records both.
Alternatives rejected
|
Approach |
Why rejected |
|---|---|
|
AWS Budgets with Budget Actions |
Billing data updates 8 to 12 hours apart, so a runaway loop runs for hours first. Kept as an account-level backstop. |
|
Proxy or API gateway in the request path |
Adds a hop to every request and changes the endpoint and authentication for Claude Code, which the customer excluded. Deferred to a later phase. |
|
Amazon Bedrock service quotas (TPM / RPM) |
Account-wide per model and limits rate, not spend. |
|
Amazon Bedrock application inference profiles |
Cost attribution only, with no blocking, and every client must call a profile ARN. |
The hardest problem
Making the cost engine count in the budget owner's unit, priced the way AWS bills it.
The first version, validated in staging, capped tokens. It worked but did not express a budget: a limit generous enough for Haiku let an Opus user spend several times more, and one tight enough for Opus blocked Haiku users well within budget. The architecture walkthrough surfaced the gap, and production went live with daily USD limits.
That USD version used one flat rate, so calculated cost drifted from the bill as the model mix changed. A change request replaced it with per-model pricing, with cache write and cache read tokens at their own rates.
The new query ran in the CloudWatch console but failed inside AWS Lambda: field aliasing, null cache-token fields and an invalid nested aggregation. The rewrite wraps every token field in coalesce, so calls without caching still count input and output cost. It was validated with a live Claude Opus 4.5 invocation.
Delivery phases
|
Phase |
When |
Work |
Deliverables |
|---|---|---|---|
|
1. Design and staging build |
From kickoff |
Token-cap version validated in staging; architecture walkthrough |
Staging deployment |
|
2. Production go-live |
Week 3 |
Limits moved to daily USD per group; deployed through Terraform and GitHub |
Production cost control and daily reset |
|
3. Per-model pricing change request |
After go-live |
Per-model and cache token rates; query rewritten for AWS Lambda |
Per-model cost engine |
|
4. Hypercare and handover |
Two weeks |
Customer's engineers take over operation |
README, runbooks, acceptance framework |
Results
The customer moved from no per-user spend control to automatic USD enforcement in production in three weeks, with 10 person-days of kloia effort.
|
Metric |
Before |
After |
Delta |
|---|---|---|---|
|
Per-user spend visibility |
Account-level monthly bill only |
Daily USD total per IAM user, updated every 10 minutes |
Monthly and account-wide to every 10 minutes, per user |
|
Time from overspend to action |
Found on the monthly bill |
Automatic block within one 10-minute cycle (end-to-end flow validated at deployment) |
Manual discovery to automatic block |
|
Cost accuracy across models |
No calculation |
Per-model rates for Claude Haiku, Sonnet and Opus, including cache tokens |
All four token types priced |
|
Changing a group's limit |
Not possible |
One Parameter Store update, applied on the next run |
No redeployment |
|
Latency added to Amazon Bedrock calls |
n/a |
None |
Zero |
|
Solution running cost (design estimate) |
n/a |
About USD 7 per month with metadata-only logs |
Under 0.3% of monthly Amazon Bedrock spend even if prompt text is logged |
Every criterion in the definition of success is met, including a solution the customer's engineers deploy through their own pipeline. Running-cost figures come from kloia's cost model, not billing actuals. Log ingestion is over 90 percent of it, so the decision on logging prompt text sets the scenario. Acceptance also requires calculated cost for a sample day within ±5% of AWS Cost Explorer.
An account-level AWS Budgets alert covers any period the control is down. Developers never notice the control until they reach a limit, and finance owns the limits.
What this unlocks
- TokenOps within the FinOps practice: per-user daily cost data enables chargeback by team, monthly budgets and trend reporting.
- Inline enforcement as a next phase: the same limits and pricing behind a gateway that rejects requests before they run, closing the 10-minute window.
- Soft limits: the per-user totals in Amazon DynamoDB can trigger warnings, for example at 80 percent, before the hard stop.
- Federated users and roles: taking the group from identity attributes extends the control to AWS IAM Identity Center users and assumed roles.
Lessons Learned
- Agree the limit's unit with finance at kickoff. Choosing dollars at design time would have saved an iteration.
- Test queries in the runtime that runs them. A query that works in the console can fail in AWS Lambda; validate against real logs, including calls without cache fields.
- State the enforcement window up front. Size limits so that one window's overshoot is acceptable.
One of the leading banks in the UAE moved from unmetered Amazon Bedrock usage to automatic per-user daily USD limits in three weeks, using a serverless, out-of-band control built on AWS Lambda, Amazon DynamoDB and an AWS IAM explicit Deny.
kloia is an AWS Premier Tier Services Partner specializing in cloud modernization, AI-driven platform engineering, and AWS Marketplace solutions.
Case Studies
Open-Source Observability Transformation on AWS
Open-Source Observability Transformation on AWS