Preserving Prompt Caching and Blocking Bedrock IAM Cost Bombs in
When teams connect AI agents to Amazon Bedrock or Claude, two cost spikes show up quickly in production: random PII redaction silently breaking prompt caching, and overly broad Bedrock IAM policies letting dev roles invo
When teams connect AI agents to Amazon Bedrock or Claude, two cost spikes show up quickly in production: random PII redaction silently breaking prompt caching, and overly broad Bedrock IAM policies letting dev roles invoke expensive models or Provisioned Throughput.
Both have straightforward fixes that take less than 15ms to enforce.
1. Why random PII placeholders kill your 90% prompt-cache discount
Prompt caching on Amazon Bedrock and Anthropic requires a byte-for-byte identical prefix across requests.
If your redaction middleware substitutes <EMAIL_8f2a> on request one and <EMAIL_c19d> on request two for the same cached system/RAG context, every request misses the cache and bills at full input token rates.
CoreNova AI Guard (PUBLIC on AWS Marketplace, $29/$99/$299/mo, zero data retention) avoids this by generating deterministic positional placeholders ([EMAIL_1], [CREDIT_CARD_1], [AWS_ACCESS_KEY_1]):
curl -s -X POST https://guard.corenovacloud.com/v1/redact \
-H "Content-Type: application/json" \
-d '{
"text": "Account owner [email protected] reported ticket #4021; escalate to [email protected].",
"return_restoration_map": true
}'
For repeated entities across multi-turn MCP tool responses, McpToolResponseGuard maintains a session map so [email protected] stays [EMAIL_1] across turns while restore_for_tool() only restores real values into allowlisted tools and fields.
2. Catching Bedrock IAM cost bombs before Terraform apply
Most IAM scanners check for iam:* or s3:*, but skip Amazon Bedrock cost-commitment actions. A role created by a coding agent with bedrock:* or bedrock:CreateProvisionedModelThroughput on Resource: "*" can lock an account into thousands of dollars of hourly commitment or let a looping agent invoke arbitrary foundation models.
We just shipped v1.4.0 of CoreNova Cloud IAM & IaC Security Audit (PUBLIC on AWS Marketplace, https://audit.corenovacloud.com) with four deterministic Bedrock checks across IAM JSON, Terraform, and CloudFormation:
-
IAM_BEDROCK_COST_COMMITMENT(CRITICAL): flagsbedrock:*,CreateProvisionedModelThroughput,UpdateProvisionedModelThroughput,CreateModelCustomizationJob, andCreateModelImportJobonResource: "*"without conditions. -
IAM_BEDROCK_UNSCOPED_INVOKE(HIGH): flagsbedrock:InvokeModel*,Converse*, andInvokeAgenton*orfoundation-model/*without explicit model/inference-profile ARN scoping. -
IAC_BEDROCK_PROVISIONED_THROUGHPUT(HIGH): flagsaws_bedrock_provisioned_model_throughputandAWS::Bedrock::ProvisionedModelThroughputin PR diffs for FinOps sign-off. -
IAC_BEDROCK_WILDCARD_INVOKE(HIGH): flags inline Terraform/CloudFormation IAM blocks grantingbedrock:InvokeModel*on*.
Test it against the live zero-retention endpoint:
curl -s -X POST https://audit.corenovacloud.com/v1/scan/iam \
-H "Content-Type: application/json" \
-d '{
"policy": {
"Statement": [{
"Sid": "DevBedrockAccess",
"Effect": "Allow",
"Action": ["bedrock:InvokeModel", "bedrock:CreateProvisionedModelThroughput"],
"Resource": "*"
}]
}
}'
Scope Resource to explicit model ARNs such as arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-haiku-20241022-v1:0 and it passes with action: "allow" and findings_count: 0.
Try both via Streamable HTTP MCP or AWS Marketplace
- Live sandboxes (no signup):
https://guard.corenovacloud.com|https://audit.corenovacloud.com - Open-source starters (MIT):
ai-guard-mcp-starter|cloud-audit-mcp-starter - Consolidated AWS billing ($29 Starter / $99 Team / $299 Business): CoreNova on AWS Marketplace
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.