Access keys
Long-term credentials that let the CLI and SDKs act as an IAM user, how to manage them, and what to use instead.
What it is
An access key is a pair of values that lets the AWS CLI, an SDK or a direct API call act as an IAM user:
- The access key ID works like a user name, for example
AKIAIOSFODNN7EXAMPLE. - The secret access key works like a password. AWS shows it once, when the key is created, and never again.
Access keys exist because programs can't type a password and an MFA code into a web page. They sign each API request instead.
The Console, CLI and SDK page shows where access keys fit among the ways to reach AWS.
How access keys work
- They are created in the IAM console, on the user's Security credentials tab. Users can manage their own keys if their policy allows it.
- Each IAM user can have at most two access keys. Two allow rotation: create the new key, switch the programs to it, then delete the old one.
- A key is Active or Inactive. Deactivating stops it working at once but keeps it, so it can be turned back on if something breaks. Deleting is permanent.
- The console shows when each key was last used, from which Region and for which service. Unused keys are a risk: delete them.
- Keys don't expire by themselves. They work until someone deactivates or deletes them.
Treat them like a password
Anyone with the access key ID and secret can do everything the user can, from anywhere in the world. Never share them, never put them in code or in a git repository, and never store them on an EC2 instance.
Better than access keys
AWS now recommends avoiding long-term access keys wherever possible:
- On a personal computer:
aws loginwith the console sign-in, or IAM Identity Center withaws configure sso. Both give short-term credentials that expire by themselves. - On EC2, Lambda, ECS and other AWS services: an IAM role. The service receives temporary credentials that AWS rotates automatically.
- In CI/CD outside AWS (for example GitHub Actions): an IAM role trusted through OpenID Connect, so no keys are stored in the CI system.
Access keys are a last resort for tools that support nothing else.
Real-world examples
- A leaked key: a developer pushes code with an access key to a public GitHub repository. Within minutes, bots find it and start launching instances for crypto-mining. The fix: deactivate and delete the key straight away, check CloudTrail for what it did, and move the app to a role.
- Rotation: a company with a legacy on-premises backup script still needs keys. Every 90 days it creates a second key, updates the script, confirms it works, and deletes the old key.
Exam tips
- "An application on EC2 needs AWS credentials" → IAM role, not access keys.
- "Access keys were exposed" → deactivate or delete them immediately, then review activity in CloudTrail.
- "Rotate access keys without downtime" → create a second key, switch over, then delete the first (two keys per user allow this).
- "Find unused or old access keys" → IAM credential report or the key's last used information.
- "Access key ID ≈ user name, secret access key ≈ password" → the way the slides frame it.
Common traps
- "Store access keys in the EC2 user data or on the instance." Anyone who can read the instance can read them. Use a role.
- "Give the root user access keys for automation." Root should never have access keys.
- "A user can have unlimited access keys." The limit is two.
Hands-on lab: create, use and remove an access key
Goal: see how access keys work end to end, then delete the key so it can't leak.
Free
IAM has no charge. The commands only read information.
Before you start: have the AWS CLI installed on your computer (see the CLI lab).
Create a test user
Open IAM → Users → Create user, name it saa-cli-test, don't give it console access, and attach the AWS managed policy ReadOnlyAccess directly.
Create an access key
Open the user → Security credentials → Create access key. Choose Command Line Interface (CLI), read the recommendation to use alternatives, tick the confirmation and create the key. Copy both values now: the secret won't be shown again.
Configure a CLI profile
aws configure --profile saa-cli-testPaste the access key ID and secret, set the Region to us-east-1 and the output to json.
Use it
aws sts get-caller-identity --profile saa-cli-test
aws s3 ls --profile saa-cli-test
aws iam create-user --user-name should-fail --profile saa-cli-testThe first two work. The last one fails with AccessDenied: the user only has read access.
Deactivate, then delete
In the console, set the key to Inactive and run aws sts get-caller-identity --profile saa-cli-test again: it now fails. Then delete the key and the saa-cli-test user.
Expected result: read-only calls succeed, a write call is denied, and the key stops working as soon as it's deactivated.
Clean up: delete the access key and the saa-cli-test user (done above), then remove the profile from ~/.aws/credentials and ~/.aws/config.