
Claude Code and Cowork on Bedrock, Part 4: Cost, Spend Controls, and Observability
Part 4 of a four-part enterprise playbook. Attribute Claude spend on Amazon Bedrock to each user and team, avoid the AWS Marketplace billing gap for Claude 5.x, enforce real spend limits with the Claude apps gateway, and set up invocation logging and CloudWatch alarms without leaking sensitive prompts. Verified November 2026.
Series: Claude Code and Cowork on Bedrock (4 articles)
- …
- 4Claude Code and Cowork on Bedrock, Part 4: Cost, Spend Controls, and Observability This article
Claude Code and Cowork on Bedrock, Part 4: Cost, Spend Controls, and Observability
Last verified November 11, 2026, against Claude Code v2.1.322, Claude Desktop v5.1231.0, and the current AWS documentation. Check the linked references before you deploy.
The series
- Part 1: The AWS foundation. Accounts, data retention, identity, and models
- Part 2: Claude Code managed settings and hardening
- Part 3: Claude Desktop and Cowork managed settings
- Part 4: Cost, spend controls, and observability (you are here)
This part assumes you've completed Part 1. You need a dedicated Bedrock account and users signing in through IAM Identity Center. That sign-in is what makes per-user attribution possible.
Coding agents are the most variable workload most organizations run on Bedrock. One developer running parallel subagents can spend more in an afternoon than a team spends in a week. This part answers three questions:
- Who spent what? Attribution per user, per team, and per request.
- How do I stop runaway spend? Real-time caps versus lagging budget alerts.
- What happened? Invocation logs and alarms, without putting sensitive prompts where they don't belong.
Step 1: Attribute cost
Question | Mechanism | Notes |
|---|---|---|
Per user | IAM principal cost allocation | Create a CUR 2.0 export with Include caller identity (IAM principal) allocation data. The CUR column is since August 2026 line_item_iam_principal . This also covers bedrock-mantle (). |
Per team | Application inference profiles (AIPs) with Team and CostCenter tags | Create each AIP by copying a geo profile ARN so it keeps cross-Region routing. Activate the tags as cost allocation tags ; new tags take up to 24 hours to appear. |
Per request | Request metadata ( requestMetadata / X-Amzn-Bedrock-Request-Metadata ) | Appears in invocation logs only, not in Cost Explorer or CUR. Not supported on bedrock-mantle . |
Per user: IAM principal cost allocation
Because every user signs in through IAM Identity Center (Part 1), each
InvokeModel call runs as that user's AWSReservedSSO_ClaudeBedrockUser_* session. Turn on caller identity in your CUR 2.0 export, and every Bedrock line item carries the principal. Query it in Athena:SELECT line_item_iam_principal, SUM(line_item_unblended_cost) AS costFROM cur2WHERE line_item_usage_start_date >= date_trunc('month', current_date) AND line_item_iam_principal LIKE '%ClaudeBedrockUser%'GROUP BY 1ORDER BY 2 DESC;Don't filter on the service code here; see the billing gotcha below. Enabling caller identity costs nothing, but it splits line items per principal, so expect larger CUR files ( AWS Cloud Financial Management blog ).
Per team: application inference profiles
aws bedrock create-inference-profile \ --inference-profile-name claude-sonnet-team-payments \ --model-source copyFrom=arn:aws:bedrock:us-east-1:111122223333:inference-profile/us.anthropic.claude-sonnet-5-5 \ --tags key=Team,value=payments key=CostCenter,value=CC-1234To route a team to its AIP, put the AIP ARN in that team's Claude Code
env (for example, ANTHROPIC_DEFAULT_SONNET_MODEL ), and scope the profile with an MDM smart group. The permission set from Part 1 already allows application-inference-profile/* . Remember to add the AIP ARN to that team's availableModels , or the exact-match allowlist from Part 2 will refuse it.Billing gotcha: Claude 5.x isn't billed under "Amazon Bedrock". Claude 5.x models are billed through AWS Marketplace, so their charges appear under the model provider, not under the "Amazon Bedrock" service (see the Pricing section of the Claude Opus 5.5 model card ). A budget, Cost Explorer filter, or CUR query keyed only on the service will miss them. Use the Bedrock product attribute filters (model, provider, inference type) that were added to Cost Explorer and AWS Budgets in October 2026 .
Step 2: Control spend
AWS Budgets refreshes up to three times a day ( Budgets best practices ), so a budget alert is a lagging signal, not a real-time meter. Pick your enforcement model with that in mind:
Option | Granularity | Notes |
|---|---|---|
Claude apps gateway for AWS | Per org, group, or user | Daily, weekly, and monthly spend limits enforced on every request. Also adds per-group model policy, telemetry, and Bedrock Guardrails. Start here if you need real caps. |
| AWS Budgets actions → SCP | Whole account | Native and automatic, but it stops everyone in the account, hours after the threshold is crossed. |
Budget → SNS → Lambda → permission set | Per permission set | Update the permission set's inline policy, then call IAM Identity Center troubleshooting ProvisionPermissionSet . You can't call iam:PutRolePolicy on the AWSReservedSSO_* roles that IAM Identity Center creates, because IAM rejects changes to those protected roles (). |
Whatever you choose, still set an AWS Budget with the Bedrock attribute filters as a monthly backstop and finance signal.
The Claude apps gateway
The Claude apps gateway is a self-hosted service that sits between your users and Bedrock. It replaces the custom Lambda kill switch and the per-user token proxy that earlier guidance relied on. The AWS guidance repository for Claude Code on Bedrock is now in maintenance mode. Sources for this section: Introducing Claude apps gateway for AWS , the gateway documentation , spend limits , and Deploy on AWS .
How it works
- It's a single Linux binary that you run on ECS Fargate or EKS, backed by PostgreSQL 11 or later (Amazon RDS works). Anthropic's Deploy on AWS guide has a worked example with Secrets Manager.
- Users sign in through your OIDC IdP: Okta, Entra ID, Google Workspace, and others. SAML and LDAP aren't supported, so put an OIDC bridge in front if you need one.
- The gateway calls
bedrock-runtimewith its own task role. Per-developer AWS cost attribution can be preserved; see the gateway configuration docs.
- Model access and managed settings are delivered per IdP group from the gateway's
managedblock. Gateway sessions don't fetch claude.ai server-managed settings.
- OTLP telemetry is stamped with the user's identity and forwarded to your collector.
Spend limits
- Caps are set through an admin API (
POST /v1/organizations/spend_limits) with{scope, amount, period}. The scope isuser,rbac_group, ororganization; the period isdaily,weekly, ormonthly; amounts are in USD cents. In Claude Desktop 4.23118.0 or later connected to the gateway, admins can also manage caps in the app.
- A group or org cap is a per-seat default, not a shared pool. Each developer's effective cap is their user override, then the most restrictive of their groups' caps, then the org default.
- Over the cap, the gateway returns
429(billing_error) until the cap resets at the UTC day, week, or month boundary. Claude Code warns users at 75% and 95%.
- Amounts are the gateway's list-price estimate, a circuit breaker rather than an invoice. Reconcile against CUR. Use
pricing.overridesif you have negotiated rates.
- If PostgreSQL is unreachable, enforcement fails open by default. Set
enforcement.fail_closed_on_error: trueif unmetered spend is unacceptable.
Connecting clients
- Claude Code: in managed settings, replace the direct-Bedrock provider keys from Part 2 with
forceLoginMethod: "gateway"andforceLoginGatewayUrl. AddparentSettingsBehavior: "merge"if Desktop will also launch embedded Claude Code sessions.
- Claude Desktop: set
bootstrapUrlto<public_url>/user/bootstrap, and opt the policy in with adesktopkey in the gateway config.
- Gateway upstreams ignore
ANTHROPIC_*_BASE_URLin the gateway's environment (as of v2.1.321). Setbase_urlon the upstream instead.
Trade-offs
- WebSearch and Remote Control aren't available on gateway sessions.
- There's no service-token flow, so CI jobs keep calling Bedrock directly with their own IAM role.
- You operate another service: high availability, PostgreSQL backups, TLS, and upgrades. Its
principal_emailstable holds PII (email, name, groups) with a 90-day default retention; include it in your DSAR and offboarding runbooks.
Step 3: Model invocation logging
Invocation logs are your system of record for what was asked and answered. In regulated industries they are also a sensitive data store, so design access before you turn them on.
Invocation logs contain full prompts and responses. That can include source code, secrets that users paste, and PHI or PII. Encrypt with a customer-managed KMS key, restrict read access to a small security role, and set retention deliberately. Logging configuration is per Region, so set it in every Region you call from. Calls to thebedrock-mantleendpoint aren't captured by invocation logging ( Model invocation logging ). In CloudWatch Logs, consider data protection masking for PII.
CloudWatch Logs destination
Bedrock has no default log group. You create the log group and a delivery role:
aws logs create-log-group --log-group-name /bedrock/claude-invocations \ --kms-key-id arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890abaws logs put-retention-policy --log-group-name /bedrock/claude-invocations --retention-in-days 90Trust policy for the delivery role:
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "bedrock.amazonaws.com" }, "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "aws:SourceAccount": "111122223333" }, "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:*" } } }]}Permissions for the role:
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["logs:CreateLogStream", "logs:PutLogEvents"], "Resource": "arn:aws:logs:us-east-1:111122223333:log-group:/bedrock/claude-invocations:log-stream:aws/bedrock/modelinvocations" }]}S3 destination
Use S3 for long-term retention and for payloads too large for CloudWatch Logs. The bucket policy:
{ "Version": "2012-10-17", "Statement": [{ "Sid": "AmazonBedrockLogsWrite", "Effect": "Allow", "Principal": { "Service": "bedrock.amazonaws.com" }, "Action": "s3:PutObject", "Resource": "arn:aws:s3:::example-bedrock-logs/AWSLogs/111122223333/BedrockModelInvocationLogs/*", "Condition": { "StringEquals": { "aws:SourceAccount": "111122223333" }, "ArnLike": { "aws:SourceArn": "arn:aws:bedrock:us-east-1:111122223333:*" } } }]}Turn on Block Public Access, default SSE-KMS encryption, and a lifecycle rule that matches your retention policy. If you use SSE-KMS, the key policy must let
bedrock.amazonaws.com generate data keys.Turn it on
aws bedrock put-model-invocation-logging-configuration --region us-east-1 --logging-config '{ "cloudWatchConfig": { "logGroupName": "/bedrock/claude-invocations", "roleArn": "arn:aws:iam::111122223333:role/BedrockInvocationLogging", "largeDataDeliveryS3Config": { "bucketName": "example-bedrock-logs", "keyPrefix": "large" } }, "s3Config": { "bucketName": "example-bedrock-logs" }, "textDataDeliveryEnabled": true, "imageDataDeliveryEnabled": false, "embeddingDataDeliveryEnabled": false}'Per-user usage from the logs
With Logs Insights:
stats count(*) as calls, sum(input.inputTokenCount) as tokens_in, sum(output.outputTokenCount) as tokens_out by identity.arn| sort tokens_out descThis gives you token-level usage per user in near real time, hours before the same spend shows up in CUR.
Step 4: Alarms
Alarm | Metric | Why |
|---|---|---|
Throttling | InvocationThrottles | Users feel throttling as a stalled agent. Request a quota increase before rollout waves. |
Client / server errors | InvocationClientErrors , InvocationServerErrors | A spike in client errors after a config push usually means a bad model ID or a missing IAM prefix. |
Latency | InvocationLatency (p99) | Catches Region or tier problems. |
Approaching quota | EstimatedTPMQuotaUsage | Warns before throttling starts. |
For spend, use AWS Budgets with the Bedrock attribute filters from Step 1 (
EstimatedCharges is an AWS/Billing metric, not a Bedrock one). CloudWatch generative AI observability provides prebuilt views of model invocations.
Step 5: Client telemetry (preview)
Invocation logs and CloudTrail show that a call happened and which IAM principal made it. OpenTelemetry from the clients adds what Bedrock can't see: sessions, tool calls, accepted edits, and cost per session. Claude Code and Claude Desktop both export it natively to a collector you run.
To try it, point Claude Code at a collector from the managed settings in Part 2 ( Claude Code monitoring ):
CLAUDE_CODE_ENABLE_TELEMETRY=1OTEL_METRICS_EXPORTER=otlpOTEL_LOGS_EXPORTER=otlpOTEL_EXPORTER_OTLP_PROTOCOL=http/protobufOTEL_EXPORTER_OTLP_ENDPOINT=https://otel.your-org.comFor Desktop, set
otlpEndpoint (and otlpProtocol , default http/protobuf ), as described in the configuration reference .Before you take this to production, keep three things in mind:
- The client's
user.ididentifies an install, not a person. Don't use it for chargeback or audit without verifying identity at the collector.
- Leave content capture off. That means Claude Code's
OTEL_LOG_USER_PROMPTSandOTEL_LOG_TOOL_DETAILS, and Desktop'sotlpContentCapture. Treat the collector as the same data class as invocation logs.
- Use OTLP over HTTP. That's what both clients' authenticated export paths support.
Coming next: a dedicated post on production-grade agent telemetry on AWS. It will cover verified per-user identity, redaction, and linking every model call to its invocation log and CloudTrail event. This series will link to it when it's published.
Clean up (pilot)
- Remove the MDM profiles (Parts 2 and 3),
/etc/aws/config, andmanaged-mcp.json.
- Unassign the
ClaudeBedrockUserpermission set.
- Delete the application inference profiles, the invocation-logging configuration (in each Region), the log group, and the S3 bucket.
- If you deployed the gateway, delete per-user caps and purge
principal_emails, then tear down the service and database.
- Leave the zero-data-retention SCP in place. It costs nothing and protects the next pilot.
Series wrap-up
Part | You built |
|---|---|
1 | A dedicated Bedrock account, SCP-locked zero data retention, SSO, and a model and Region strategy |
2 | A Claude Code profile with a Bedrock-only provider, exact model allowlists, the sandbox, managed plugins, and hooks |
3 | A Desktop and Cowork profile with in-app SSO, model list, workspace and egress limits, plugins, retention, and migration |
4 | Per-user and per-team attribution, real spend caps, invocation logs, and alarms |
References
Cost and billing
Claude apps gateway
Logging and monitoring
Opinions are my own. Configuration keys and model IDs change frequently; verify against the documentation above before deploying.
Series: Claude Code and Cowork on Bedrock (4 articles)
- …
- 4Claude Code and Cowork on Bedrock, Part 4: Cost, Spend Controls, and Observability This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article