Cloud and hosting

AWS (IAM access keys) API keys: find, store, rotate, and use them safely with AI agents

Last checked 2026-10-25 against AWS (IAM access keys)'s documentation

AWS IAM access keys are created in the IAM console under Users → your user → Security credentials → Create access key. Each key is a pair, an access key ID (starts with AKIA for long-term keys) and a secret access key that is shown only once. AWS recommends temporary credentials from IAM roles or IAM Identity Center instead of long-term keys.

AWS (IAM access keys) key types

TypePrefixSecret?ScopeExpiry
Long-term access key (IAM user or root)
An IAM user can have a maximum of two access keys. The secret access key can be retrieved only when the key is created.
AKIAYesWhatever the IAM user's policies allow; there is no separate key scopeDoes not expire unless you deactivate or delete it
Temporary access key (from AWS STS)
Used together with AWS_SESSION_TOKEN.
ASIAYesThe permissions of the role or session that issued itExpires; the credentials include a session token with an expiry time

How to create a AWS (IAM access keys) key

  1. Sign in to the AWS Management Console and open the IAM console.
  2. In the navigation pane, choose Users, then choose the user.
  3. Open the Security credentials tab.
  4. In Access keys, choose Create access key, pick a use case, then choose Next.
  5. Choose Create access key, then Show or Download .csv file to save the secret access key. This is the only time you can see it.

Open AWS (IAM access keys)'s key settings

Limiting what the key can do

Access keys carry the permissions of the IAM user they belong to, so narrow access by attaching least-privilege IAM policies to a dedicated user, or avoid user keys by using IAM roles for temporary credentials. AWS says not to create access keys for the root user.

How to rotate a AWS (IAM access keys) key

  1. While the first key is active, create a second access key (aws iam create-access-key or the console).
  2. Update all applications and tools to use the new key.
  3. Check the old key's Last used information (aws iam get-access-key-last-used).
  4. Deactivate the old key (aws iam update-access-key with status Inactive) and confirm nothing breaks.
  5. After a waiting period, delete the old key (aws iam delete-access-key).

AWS recommends deactivating before deleting, and you can reactivate the old key if something still depends on it.

How to revoke a AWS (IAM access keys) key

  1. In the IAM console, open the user's Security credentials tab.
  2. In Access keys, choose Actions, then Deactivate to stop the key working immediately.
  3. When you are sure nothing uses it, choose Actions, then Delete.

If your AWS (IAM access keys) key leaked

  1. Deactivate the exposed key straight away (aws iam update-access-key --access-key-id <key id> --user-name <user> --status Inactive).
  2. Review CloudTrail for activity by that access key ID and remove any resources or IAM users, roles or keys you did not create.
  3. Delete the exposed key and create a replacement, stored in a secrets manager rather than in code.
  4. If AWS has attached the AWSCompromisedKeyQuarantine policy to the user, remove it only after the key is replaced and the account is clean.

Environment variables and CLI

AWS (IAM access keys)'s SDKs and docs read the key from AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_PROFILE, AWS_DEFAULT_REGION or AWS_REGION.

AWS CLI (aws): aws configure for access keys, aws configure sso for IAM Identity Center, or aws login for console credentials (short-term)

Things that catch people out

  • The secret access key is shown only once; if you lose it you must delete the key and create a new one.
  • Access keys in ~/.aws/credentials are stored in plaintext.
  • A key starting ASIA is temporary and needs AWS_SESSION_TOKEN as well, or requests fail.
  • Each IAM user can hold only two access keys, which is what makes zero-downtime rotation possible.

Recent incidents that put AWS (IAM access keys) keys at risk

If you were affected by one of these, rotate your AWS (IAM access keys) keys using the rotation steps above.

Using your AWS (IAM access keys) key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a AWS (IAM access keys) key, these intents fit:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
cli_loginLets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.
capture_secretPlanned, not built yet: will read a newly created key straight from the page or command output into the vault.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my AWS access key ID and secret access key?

The access key ID is listed under IAM → Users → your user → Security credentials. The secret access key cannot be viewed again after creation; if it is lost, create a new key.

How do I rotate an AWS access key?

Create a second key, switch your apps to it, deactivate the old key, confirm nothing breaks, then delete the old key. A user can hold at most two keys, so this is the supported pattern.

What does an AWS access key starting with AKIA or ASIA mean?

AKIA marks a long-term key for an IAM user or the root user. ASIA marks temporary credentials issued through AWS STS.

Should I use AWS access keys at all?

AWS says to prefer temporary credentials from IAM roles or IAM Identity Center, and to use long-term keys only when there is no alternative.

Can an AI agent use my AWS (IAM access keys) key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with list_credentials, run_with, store_secret, so the agent gets the result and never the value.

Stop pasting AWS (IAM access keys) keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.