# aws iam create-access-key

AWS CLI commands · Updated 16 November 2026

**Short answer:** aws iam create-access-key --user-name my-user creates a new long-term access key ID and secret for an IAM user. The secret is shown only in this response, each user can have at most two keys, and for people (as opposed to legacy automation) temporary credentials from IAM Identity Center or roles are the better choice.

## What the command does

It generates a key pair for the named IAM user and returns it once:

```
{
  "AccessKey": {
    "UserName": "ci-deploy",
    "AccessKeyId": "AKIAIOSFODNN7EXAMPLE",
    "Status": "Active",
    "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    "CreateDate": "2026-11-16T09:30:00+00:00"
  }
}
```

If you omit `--user-name`, the key is created for the IAM user making the call. The new key is active immediately, though as with other IAM changes it can take a few seconds before every AWS endpoint accepts it.

## Syntax

```
aws iam create-access-key [--user-name <user>]
```

## Worked examples

**Create a key and write it straight into a CLI profile**, without printing the secret to the terminal:

```
read -r id secret <<EOF
$(aws iam create-access-key --user-name ci-deploy \
  --query "AccessKey.[AccessKeyId,SecretAccessKey]" --output text)
EOF
aws configure set aws_access_key_id "$id" --profile ci-deploy
aws configure set aws_secret_access_key "$secret" --profile ci-deploy
unset secret
```

**Store it in Secrets Manager** for an application to read instead:

```
aws iam create-access-key --user-name legacy-ftp-sync --output json > /tmp/key.json
aws secretsmanager create-secret --name legacy-ftp-sync/aws-key \
  --secret-string file:///tmp/key.json
shred -u /tmp/key.json
```

**Check the user is below the two-key limit first:**

```
aws iam list-access-keys --user-name ci-deploy \
  --query "AccessKeyMetadata[].[AccessKeyId,Status,CreateDate]" --output text
```

**Rotation pattern**: create the new key, deploy it, confirm the old key is no longer used, deactivate, then delete. See [rotating IAM access keys](https://cloudconsole.dev/how-to/rotate-iam-access-keys) and [update-access-key](https://cloudconsole.dev/cli/iam-update-access-key).

## Letting users manage their own keys

If some IAM users must keep keys, let them rotate their own rather than routing every rotation through an administrator. An identity-based policy that allows `iam:CreateAccessKey`, `iam:UpdateAccessKey`, `iam:DeleteAccessKey` and `iam:ListAccessKeys` on `arn:aws:iam::123456789012:user/${aws:username}` limits each user to their own keys. Pair it with an MFA condition for anything sensitive.

## When not to create an access key

| You are… | Use instead |
|---|---|
| A person using the CLI | IAM Identity Center and [aws sso login](https://cloudconsole.dev/cli/sso-login), which gives short-lived credentials |
| Code on EC2, ECS, Lambda | The instance profile, task role or execution role |
| CI in GitHub Actions or similar | OIDC federation to an IAM role |
| Another AWS account | A cross-account role and [sts assume-role](https://cloudconsole.dev/cli/sts-assume-role) |
| Root user | Never. Delete root keys if any exist |

## Gotchas

- **The secret cannot be retrieved later.** Lose it and the only fix is a new key.
- **`LimitExceeded`** means the user already has two keys, active or inactive. Delete an unused one first.
- **Keys leak through history and logs.** Do not paste the JSON into chat or tickets, and avoid echoing it in CI output.
- **"Identity Center create access key" is a different thing.** Identity Center users cannot have long-term IAM keys. The access portal shows short-lived credentials per account and role, and the CLI fetches the same via SSO.
- **Least privilege still applies.** A key is only as dangerous as the user's policies. Review them with [simulate-principal-policy](https://cloudconsole.dev/cli/iam-simulate-principal-policy).

## Questions

### How do I create access keys for IAM Identity Center users?

You do not; Identity Center issues temporary credentials. Configure a profile with aws configure sso and run aws sso login, or copy the short-term keys from the access portal.

### How many access keys can an IAM user have?

Two at a time. That allows rotation: create a second key, move to it, then delete the first.

### How do I create an access key for myself?

Run aws iam create-access-key without --user-name while authenticated as that IAM user. You need iam:CreateAccessKey on your own user.

## When this happens away from your desk

Key rotation is the kind of chore that slips until an audit finding forces it. CloudConsole is built with production guardrails in mind and to show the state of your AWS resources on a phone.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [aws iam create-access-key (AWS CLI Command Reference)](https://docs.aws.amazon.com/cli/latest/reference/iam/create-access-key.html)
- [Manage access keys for IAM users (IAM User Guide)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)

## Related

- [aws iam list-access-keys](https://cloudconsole.dev/cli/iam-list-access-keys)
- [aws iam update-access-key](https://cloudconsole.dev/cli/iam-update-access-key)
- [How to rotate IAM access keys](https://cloudconsole.dev/how-to/rotate-iam-access-keys)
- [aws configure](https://cloudconsole.dev/cli/configure)
- [How to set up IAM Identity Center](https://cloudconsole.dev/how-to/set-up-iam-identity-center)
- [aws iam create-role](https://cloudconsole.dev/cli/iam-create-role)

---

Source: https://cloudconsole.dev/cli/iam-create-access-key

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
