---
title: Should AI agents use Amazon Bedrock API keys or IAM roles?
url: https://opencontroller.lyzr.com/blog/bedrock-api-keys-vs-iam-roles-for-ai-agents
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# Should AI agents use Amazon Bedrock API keys or IAM roles?

**For production AI agents, use IAM roles, and if a tool insists on a bearer token, use a short-term Amazon Bedrock API key generated from that role. AWS itself says long-term Bedrock API keys are for exploration only. Short-term keys last at most 12 hours, so agents need a refresh pattern, not a stored secret.**

This question comes up in almost every agent deployment on AWS. A framework or gateway supports "API key" auth, a developer generates a long-term key, and six months later nobody knows who owns it. Here is how the options compare and what to standardise on.

## What are the three ways an agent can authenticate to Bedrock?

Amazon Bedrock accepts three credential patterns. They differ in lifetime, blast radius and how easy they are to audit.

| Option | Lifetime | What it is tied to | AWS guidance | Fit for agents |
|---|---|---|---|---|
| IAM role (SigV4) | Temporary STS credentials, refreshed by the SDK | The agent's runtime role | Standard AWS pattern | Best default |
| Short-term Bedrock API key | Up to 12 hours, or the session length if shorter | The IAM principal that generated it; same Region only | "Recommended for production use" | Good when a client needs a bearer token |
| Long-term Bedrock API key | Until the expiry you set | A new IAM user with attached policies | "Recommended only for exploration" | Avoid in production |

The long-term option is the risky one. Generating it creates an IAM user and a service-specific credential. That user outlives the project unless someone deletes it, and the key works from anywhere until it expires.

## Why do short-term keys expire after 12 hours, and is that a problem?

A short-term key is derived from the credentials of the principal that creates it. It inherits that principal's permissions and expires when the session does, with a hard maximum of 12 hours. It also only works in the AWS Region where it was generated.

For a long-running agent this is a feature, not a bug. The fix is to generate the token at call time rather than store it. AWS publishes token generator libraries for Python (`aws-bedrock-token-generator`), JavaScript (`@aws/bedrock-token-generator`) and Java. The documented pattern is to call the provider before each request: it returns a cached token while valid and mints a new one when needed.

So the agent still runs under an IAM role. The bearer token is just a short-lived wrapper the role produces on demand.

## How do you stop teams creating long-term keys?

Bedrock exposes IAM controls for both creating and using keys:

1. **Control creation.** Long-term keys are created with `iam:CreateServiceSpecificCredential`. Use the `iam:ServiceSpecificCredentialAgeDays` condition key to cap expiry (for example 90 days), or deny the action outright in production accounts.
2. **Control use.** Calls made with a key require `bedrock:CallWithBearerToken`. The `bedrock:bearerTokenType` condition key takes `SHORT_TERM` or `LONG_TERM`, so you can deny long-term keys while allowing short-term ones. The Bedrock Mantle endpoint has the equivalent `bedrock-mantle:CallWithBearerToken` action.
3. **Apply it org-wide.** Put the deny in a service control policy so a single account cannot opt out. Pair it with the model restrictions described in [restricting Bedrock models with SCPs](/blog/restrict-amazon-bedrock-models-with-scps).
4. **Find what already exists.** List IAM users holding Bedrock service-specific credentials and check their last use. Treat any without an owner as a leaked-key risk, as covered in [finding leaked and unused LLM API keys](/blog/find-leaked-and-unused-llm-api-keys).

## What should you check when a key is compromised?

The response differs by key type. A long-term key can be deactivated, reset or deleted through the IAM service-specific credential APIs. A short-term key cannot be revoked individually: you invalidate the session that generated it, or attach a policy denying `bedrock:CallWithBearerToken` to the principal.

Note that CloudTrail logs every Bedrock API call, but the key itself is sent in the Authorization header and is not logged. Your investigation therefore depends on mapping calls back to the principal, which is easy for roles and painful for orphaned IAM users.

## What does a sensible standard look like?

A workable standard for agent teams:

1. Every agent runtime gets its own IAM role. Do not share roles across agents; see [whether AI agents should share a service account](/blog/should-ai-agents-share-a-service-account).
2. SDK-based agents use SigV4 with that role. No keys at all.
3. Tools that need a bearer token use short-term keys minted by the role at request time.
4. Long-term keys are blocked in production by SCP and capped at a short expiry in sandboxes.
5. Gateways that front Bedrock authenticate with their own role and attribute spend per agent, so individual agents never hold Bedrock credentials.
6. Review credential age and owner monthly, in line with [how often to rotate AI agent credentials](/blog/how-often-to-rotate-ai-agent-credentials).

This sits inside the wider pattern for [governing agents across platforms](/blog/how-to-govern-ai-agents-across-platforms): one identity per agent, short-lived credentials, and a record of who owns what.

## How Opencontroller does this

Opencontroller auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, so long-term Bedrock keys and the IAM users behind them show up in the inventory with their owners. Posture flags risky permission and configuration patterns. Agents can call Bedrock through the Lyzr Gateway, which routes requests with fallback and retry and attributes cost per agent and per version, and Opencontroller supports agent workload identity federation for short-lived credentials. See the [capability reference](/capability-reference) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Can a short-term Bedrock API key be used in another Region?**
No. AWS documents that a short-term key works only in the Region where it was generated. Generate a new key in each Region the agent calls.

**Are Bedrock API key values logged in CloudTrail?**
No. CloudTrail logs the API calls, but the key travels in the Authorization header and is not logged. Attribute activity through the IAM principal instead.

**Can I allow short-term keys but block long-term ones?**
Yes. Deny `bedrock:CallWithBearerToken` with a condition on `bedrock:bearerTokenType` equal to `LONG_TERM`, and restrict `iam:CreateServiceSpecificCredential` for Bedrock.

## Key facts

- Amazon Bedrock API keys come in two types: short-term (up to 12 hours or the session length, inherit the generating IAM principal's permissions, Region-bound, recommended by AWS for production) and long-term (create an IAM user with a service-specific credential, recommended only for exploration).
- Production agents should use an IAM role with SigV4; where a bearer token is required, mint short-term keys at request time with AWS token generator libraries (Python aws-bedrock-token-generator, JavaScript @aws/bedrock-token-generator, Java).
- IAM controls: iam:CreateServiceSpecificCredential with iam:ServiceSpecificCredentialAgeDays limits long-term key creation; bedrock:CallWithBearerToken with bedrock:bearerTokenType (SHORT_TERM or LONG_TERM) controls key use; bedrock-mantle:CallWithBearerToken covers the Mantle endpoint.
- CloudTrail logs Bedrock calls but not API key values.
- Opencontroller by Lyzr auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, supports agent workload identity federation, and its LLM Gateway attributes cost per agent and version.
- Opencontroller pricing starts from $250K per deployment per year.

## Related

- [How do you restrict which Amazon Bedrock models agents can use?](https://opencontroller.lyzr.com/blog/restrict-amazon-bedrock-models-with-scps.md)
- [How do you find leaked or unused LLM API keys?](https://opencontroller.lyzr.com/blog/find-leaked-and-unused-llm-api-keys.md)
- [How often should AI agent credentials be rotated?](https://opencontroller.lyzr.com/blog/how-often-to-rotate-ai-agent-credentials.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
