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

Source: https://botpassword.com/keys/aws
Last checked: 2026-10-25

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Long-term access key (IAM user or root) | `AKIA` | Yes | Whatever the IAM user's policies allow; there is no separate key scope | Does not expire unless you deactivate or delete it |
| Temporary access key (from AWS STS) | `ASIA` | Yes | The permissions of the role or session that issued it | Expires; 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.

## 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`).

## 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 the 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

- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
- `AWS_SESSION_TOKEN`
- `AWS_PROFILE`
- `AWS_DEFAULT_REGION`
- `AWS_REGION`

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `list_credentials`: Lists the credentials this agent is granted and what it may do with each. Never values.
- `run_with`: Runs 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_login`: Lets 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.
- `rotate`: Partly 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_secret`: Saves a value the agent already holds as a new vault item.
- `capture_secret`: Planned, not built yet: will read a newly created key straight from the page or command output into the vault.

## FAQ

### 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.

## Sources

- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id-credentials-access-keys-update.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds-programmatic-access.html
- https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
