---
title: How can AI agents call Amazon Bedrock from outside AWS without long-term keys?
url: https://opencontroller.lyzr.com/blog/authenticate-to-bedrock-from-outside-aws-without-long-term-keys
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# How can AI agents call Amazon Bedrock from outside AWS without long-term keys?

**Use federation, not stored keys. Workloads with a certificate can use IAM Roles Anywhere; workloads with an OIDC identity from another cloud, Kubernetes or CI can use `AssumeRoleWithWebIdentity`; and both can mint short-term Amazon Bedrock API keys if the client needs a bearer token. AWS recommends long-term Bedrock API keys only for exploration, and short-term keys last at most 12 hours, so any runtime outside AWS needs an automatic refresh path.**

This question came up in a live enterprise deployment: an LLM gateway running outside AWS needed to call Bedrock models, the team had been handed long-term keys, and the security team pointed out that Amazon discourages them. Here is how to choose a better option. Facts come from the [Amazon Bedrock API keys documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html) and the IAM guide to [alternatives to long-term access keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds-programmatic-access.html). For the in-AWS case, see [Bedrock API keys vs IAM roles for AI agents](/blog/bedrock-api-keys-vs-iam-roles-for-ai-agents), and for how agent identity fits together overall, see the [on-behalf-of delegation pillar](/blog/ai-agent-identity-on-behalf-of-delegation).

## What are the options?

| Option | How it works | Credential lifetime | Fits when |
|---|---|---|---|
| IAM Roles Anywhere | Workload presents an X.509 certificate from a trust anchor you register (AWS Private CA or your own CA) and receives temporary role credentials | Temporary session, refreshed by the credential helper | On-premises servers, VMs in other clouds, anywhere with a PKI |
| `AssumeRoleWithWebIdentity` | Workload presents an OIDC token from a registered identity provider (another cloud's workload identity, Kubernetes service account issuer, CI provider) | Temporary session, typically 1 hour, up to the role's maximum | Workloads that already have an OIDC identity |
| Short-term Bedrock API key | Bearer token generated from an existing IAM principal's credentials | Up to 12 hours or the session length, whichever is shorter; valid only in the Region where generated | Clients that only accept a bearer token |
| Long-term Bedrock API key | Creates an IAM user with a service-specific credential and a configured expiry | Until expiry date | Exploration only, per AWS guidance |
| IAM user access keys | Static access key pair | Until rotated | Avoid |

## How do short-term Bedrock API keys fit in?

Short-term keys are not a separate identity. They inherit permissions from the IAM principal that generated them. So the real question is still how that principal gets credentials outside AWS. The common pattern is:

1. The workload obtains temporary role credentials through Roles Anywhere or web identity federation.
2. It generates a short-term Bedrock API key from those credentials, using AWS's token generator libraries (Python, JavaScript and Java are documented).
3. It calls the token generator before each request; the library returns a cached token while valid and creates a new one when needed.

If your client can sign requests with SigV4, you can skip the bearer token entirely and use the temporary credentials directly.

Remember the Region limit: a short-term key works only in the Region where it was created. A gateway that routes to several Bedrock Regions needs a key per Region.

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

AWS provides IAM controls for exactly this:

- `iam:CreateServiceSpecificCredential` controls who can create long-term keys. The `iam:ServiceSpecificCredentialAgeDays` condition key caps their expiry, for example 90 days.
- `bedrock:CallWithBearerToken` controls use of API keys at the Bedrock endpoint. The `bedrock:bearerTokenType` condition key accepts `SHORT_TERM` or `LONG_TERM`, so you can deny long-term keys while allowing short-term ones.
- All Bedrock API calls are logged in CloudTrail; the keys themselves are passed as headers and are not logged.

A sensible guardrail: deny `bedrock:CallWithBearerToken` where `bedrock:bearerTokenType` is `LONG_TERM` in production accounts, using a service control policy or permissions boundary.

## Checklist for an LLM gateway calling Bedrock from outside AWS

- [ ] One IAM role per gateway deployment, with Bedrock invoke permissions limited to approved models and inference profiles.
- [ ] Federation chosen: Roles Anywhere (certificate) or web identity (OIDC).
- [ ] Refresh handled by the SDK, credential helper or token generator, tested past the session expiry.
- [ ] Per-Region short-term keys if bearer tokens are used.
- [ ] Long-term Bedrock keys denied in production accounts.
- [ ] Existing long-term keys inventoried and retired. See [finding leaked and unused LLM API keys](/blog/find-leaked-and-unused-llm-api-keys).
- [ ] CloudTrail reviewed for calls from the gateway role.

## How Opencontroller does this

Opencontroller auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, so existing long-term Bedrock keys show up in the inventory. Posture flags risky permission and configuration patterns, and agent workload identity federation supports moving agents off static secrets. The Opencontroller LLM Gateway (Lyzr Gateway) can route to Bedrock models alongside other providers, with fallback and retry, caching and cost attribution per agent and per version; see [routing Bedrock models through an LLM gateway](/blog/route-bedrock-models-through-an-llm-gateway). [Book a demo](https://www.lyzr.ai/book-demo/) to review your Bedrock credential setup.

## Frequently asked questions

**How long does a short-term Amazon Bedrock API key last?**
Up to 12 hours, or the length of the session used to create it if that is shorter. It is valid only in the Region where it was generated.

**Does AWS recommend long-term Bedrock API keys for production?**
No. AWS documents long-term keys as suitable for exploration only and recommends short-term keys for production.

**Can I block long-term Bedrock API keys across an organisation?**
Yes. Deny `bedrock:CallWithBearerToken` when the `bedrock:bearerTokenType` condition key equals `LONG_TERM`, and restrict `iam:CreateServiceSpecificCredential`.

## Key facts

Amazon Bedrock API keys: short-term keys last up to 12 hours or the session length (whichever shorter), inherit permissions of the generating IAM principal, are valid only in the Region generated, and are recommended for production; long-term keys create an IAM user with a service-specific credential and are recommended only for exploration. Token generator libraries exist for Python, JavaScript, Java. IAM controls: iam:CreateServiceSpecificCredential with iam:ServiceSpecificCredentialAgeDays; bedrock:CallWithBearerToken with bedrock:bearerTokenType SHORT_TERM or LONG_TERM. API calls are logged in CloudTrail; keys are not. Outside AWS, use IAM Roles Anywhere (X.509 trust anchor) or AssumeRoleWithWebIdentity (OIDC) for temporary credentials. Opencontroller auto-discovers agents, models and API keys across AWS, Azure, Google Cloud; Posture flags risky permissions; agent workload identity federation; LLM Gateway routes to Bedrock with cost attribution per agent and version.

## Related

- [Should AI agents use Amazon Bedrock API keys or IAM roles?](https://opencontroller.lyzr.com/blog/bedrock-api-keys-vs-iam-roles-for-ai-agents.md)
- [How does workload identity federation work for AI agents?](https://opencontroller.lyzr.com/blog/workload-identity-federation-for-ai-agents.md)
- [Why do Amazon Bedrock calls fail through an LLM gateway, and how do you fix them?](https://opencontroller.lyzr.com/blog/route-bedrock-models-through-an-llm-gateway.md)
- [More on Agent identity and access](https://opencontroller.lyzr.com/blog/cluster/agent-identity-and-access)
