| published by | Zeen Rachidi |
|---|---|
| in blog | The New Stack |
| published date | 2026-11-29 |
| original entry | Three AI agents share one IAM role. Which one ran up the bill? |
Since April, AWS has been able to charge Bedrock inference to an IAM user or role, so Cost Explorer can tell you that a role called research-agent-2 ran up the biggest AI line of the month; but what it can’t tell you is who research-agent-2 is. Unless somebody tagged the role, the best you’re going to get is an ARN and a shrug. In effect, you’ve issued a corporate card to an employee with no manager.
Now, the public preview of AWS’s FinOps Agent traces cost changes to the responsible user or role and passes the findings to the responsible teams through Jira; if a role is untagged, the trace has nowhere to land.
This is not a minor inconvenience. The FinOps Foundation’s State of FinOps 2026 found that 98% of its 1,192 respondents now manage AI spend, up from 31% two years earlier. Forecasting won’t save you either. A study of frontier models on SWE-bench Verified found that repeated runs of the same task could differ by as much as 30x in tokens, with the priciest runs typically about double the cheapest. Models asked to estimate their own usage beforehand consistently underestimated. If neither the task nor the model can say what a run will cost, budgets become aspirational. Attribution after the fact is the only control left.
“If neither the task nor the model can say what a run will cost, budgets become aspirational. Attribution after the fact is the only control left.”
The role is where the bill, the risk, and the owner have to meet. The earlier pieces in this series covered attaching an owner at discovery, reassigning one before a last day, and what happens when the owner is an agent. This one applies the same strategy to the identity that does the spending: a query, a policy, and a clock.
Bedrock spend carries the caller’s identity only if you ask for it. In Data Exports, create a CUR 2.0 export and select “Include caller identity (IAM principal) allocation data.” Existing exports don’t gain the column retroactively, so this is a new export. Principal tags then appear in the tags map with an iamPrincipal/ prefix, which makes the question simple: which callers have spend and no owner?
SQL
SELECT
line_item_iam_principal AS principal,
element_at(tags, 'iamPrincipal/owner') AS owner,
SUM(line_item_unblended_cost) AS cost
FROM cur_table
WHERE line_item_product_code IN ('AmazonBedrock', 'AmazonBedrockService')
AND billing_period = DATE_FORMAT(CURRENT_DATE, '%Y-%m')
AND line_item_iam_principal IS NOT NULL
AND (element_at(tags, 'iamPrincipal/owner') IS NULL
OR NOT regexp_like(element_at(tags, 'iamPrincipal/owner'),
'^[^@\s]+@[^@\s]+\.[^@\s]+$'))
GROUP BY 1, 2
ORDER BY cost DESC
The query is adapted from the Athena examples in AWS’s cost attribution series. It returns every role or user with Bedrock spend this month whose owner tag is missing or isn’t an email address, so a team name or an agent’s name fails the same test as a blank. element_at returns null for a missing key instead of failing. Rows with no caller identity at all are excluded; those are Bedrock charges attributed to nobody, and they deserve a count of their own.
Two limits belong next to it. AWS attribution covers Bedrock model inference, so compute, storage, and tool costs bill as they always did. As usual, the result is a list of questions, not convictions: each row is a role someone asked for once, and that someone must be known.
An expense report tells you what was spent. A budget tells someone before it’s spent. Once an owner is active as a cost allocation tag, AWS Budgets can filter on it, so each owner can get an alert when the roles they answer for cross a threshold. No extra tooling is involved, and it’s the closest thing to a spending limit a role with unpredictable token counts can get.
The query finds roles that already exist. An env zero approval policy attached to the project where agents deploy can stop new ones from arriving anonymously. The rules are plain OPA/Rego over standard Terraform plan JSON, so they run anywhere you check plans. They make two demands:
owner tag holding a person’s email address.
package env0
import future.keywords.contains
import future.keywords.every
import future.keywords.if
import future.keywords.in
email_pattern := `^[^@\s]+@[^@\s]+\.[^@\s]+$`
# env zero wrapper: reads env zero's plan input, including Terragrunt run-all.
# For conftest, delete from here to the core rules and use: resource_changes := input.resource_changes
tf_plan(p) if {
is_object(p)
p.format_version
}
standard_plan if {
not input.plan.is_run_all
tf_plan(input.plan)
}
run_all_plan if {
input.plan.is_run_all == true
is_object(input.plan.modules)
count(input.plan.modules) > 0
every _, m in input.plan.modules {
tf_plan(m)
}
}
resource_changes := object.get(input.plan, "resource_changes", []) if standard_plan
resource_changes := [rc |
some _, m in input.plan.modules
some rc in object.get(m, "resource_changes", [])
] if run_all_plan
deny contains msg if {
not standard_plan
not run_all_plan
msg := "Unsupported plan format for the role policy"
}
# Core rules: work with any Terraform plan JSON that defines resource_changes.
# Identities whose Bedrock calls AWS can attribute, and policies that grant those calls.
principal_types := {"aws_iam_role", "aws_iam_user"}
policy_types := {"aws_iam_policy", "aws_iam_role_policy", "aws_iam_user_policy"}
spend_prefixes := ["bedrock:", "bedrock-agentcore:"]
writes(rc) if "create" in rc.change.actions
writes(rc) if "update" in rc.change.actions
as_list(x) := x if is_array(x)
as_list(x) := [x] if not is_array(x)
owner_of(rc) := rc.change.after.tags_all.owner if is_object(rc.change.after.tags_all)
owner_of(rc) := rc.change.after.tags.owner if {
not is_object(rc.change.after.tags_all)
is_object(rc.change.after.tags)
}
# Allow statements that reach a Bedrock action on every resource.
wildcard_grant(doc) if {
some st in as_list(doc.Statement)
st.Effect == "Allow"
some a in as_list(object.get(st, "Action", []))
some p in spend_prefixes
startswith(lower(a), p)
"*" in as_list(object.get(st, "Resource", []))
}
wildcard_grant(doc) if {
some st in as_list(doc.Statement)
st.Effect == "Allow"
"*" in as_list(object.get(st, "Action", []))
"*" in as_list(object.get(st, "Resource", []))
}
deny contains msg if {
some rc in resource_changes
principal_types[rc.type]
writes(rc)
not owner_of(rc)
msg := sprintf("%s: IAM identity needs an owner tag so its spend has a name", [rc.address])
}
deny contains msg if {
some rc in resource_changes
principal_types[rc.type]
writes(rc)
o := owner_of(rc)
not regex.match(email_pattern, sprintf("%v", [o]))
msg := sprintf("%s: owner must be a person's email, got %v", [rc.address, o])
}
deny contains msg if {
some rc in resource_changes
policy_types[rc.type]
writes(rc)
rc.change.after_unknown.policy == true
msg := sprintf("%s: policy document not known until apply, cannot be checked", [rc.address])
}
deny contains msg if {
some rc in resource_changes
policy_types[rc.type]
writes(rc)
is_string(rc.change.after.policy)
not json.is_valid(rc.change.after.policy)
msg := sprintf("%s: policy document is not valid JSON", [rc.address])
}
deny contains msg if {
some rc in resource_changes
policy_types[rc.type]
writes(rc)
doc := json.unmarshal(rc.change.after.policy)
wildcard_grant(doc)
msg := sprintf("%s: grants Bedrock actions on every resource, scope it to this agent", [rc.address])
}
allow if count(deny) == 0
To run the same rules in conftest or another CI step, delete the block marked as the env zero wrapper, rename the package to main, and add resource_changes := input.resource_changes. Then feed it the output of terraform show -json. The difference is enforcement: a CI check runs only if the pipeline runs it, while an approval policy sits on the project itself, so a deployment can’t skip it.
The owner is read from tags_all first, which is where the AWS provider merges default_tags, then from tags. Policy documents are parsed from the plan, so a policy that isn’t known until apply is denied, since nobody can check a value that doesn’t exist yet, and so is one that isn’t valid JSON. Allow statements are matched on the bedrock: and bedrock-agentcore: prefixes, case-insensitively, plus the all-actions-on-all-resources grant. Deny statements are ignored. The plan handling is the same as before: standard plans and Terragrunt run-all pass; anything unrecognized is denied. The tag cases use plan JSON written to match the provider documentation, so deploy one tagged role with ENV0_PRINT_POLICY_INPUT=true and check where your provider stores its tags.
“A role shared by several agents is essentially a communal corporate card, and since spend can only be attributed to the role, it somewhat defeats the purpose.”
What it can’t see matters as much. A managed policy attached by ARN is never inspected. Inline policies, NotAction, and conditions aren’t evaluated. Roles created from the console or another pipeline never pass through the check. A role shared by several agents is essentially a communal corporate card, and since spend can only be attributed to the role, it somewhat defeats the purpose. For shared roles, AWS supports a distinct RoleSessionName or session tags, and the role’s trust policy has to allow sts:TagSession.
Attribution doesn’t backfill, so the date you switch it on is the date the history begins. Tags appear for activation only after the principal has made at least one Bedrock call, and AWS says tag keys can take up to 24 hours to appear and another 24 to activate. Cost allocation tags aren’t retroactive: only costs incurred after activation are tagged, and activation happens from the management account or a standalone one, not a member account. Every week of delay is a week of spend that will never get a name.
The order that works is short. Tag the roles you know about. Activate owner as a cost allocation tag. Create the export with caller identity. Set a budget per owner. Run the query after a day, and again each month.
Then plan the exit. Most agent roles exist for a project, not forever, and a role nobody remembers is how orphaned spend starts. Where a role is meant to be temporary, put it in an environment with a TTL so it leaves when the work does.
“You shouldn’t be learning about a role’s existence from an invoice. Until it has a manager, it reports to Finance.”
Try it yourself, no purchase required. The Rego above runs in conftest for free. If you’d rather enforce it at deploy time, env zero’s Free plan includes custom approval policies and environment TTL, and CloudQuery’s Platform free tier can sync the roles themselves, so the owner tag can be checked against your directory the same way it did for resources.
You shouldn’t be learning about a role’s existence from an invoice. It’s a hot potato that arrives monthly, is addressed to an account instead of a person, and gets passed around until it lands in the lap of whoever answers emails fastest. While blame was being passed around, the role kept spending because agents only consume the budget; until it has a manager, it reports to Finance.
YOUTUBE.COM/THENEWSTACK
Tech moves fast, don't miss an episode. Subscribe to our YouTube channel to stream all our podcasts, interviews, demos, and more.