In short
One access key pushed to a public GitHub repo can be found by bots within minutes and used to run crypto miners on your card. Treat access keys like cash: carry as few as possible, for as short a time as possible.
Access keys are long-term credentials for programmatic access, and leaked keys pushed to public GitHub repositories are a common cause of compromised accounts. Prefer temporary credentials from roles or IAM Identity Center, and rotate or delete any long-term keys you must keep.

Think of it like this
Your house key under the doormat
A spare key under the mat is convenient, and anyone who looks finds it. Long-term access keys in code or a public repo are that key. Temporary credentials are more like a hotel key card that stops working when you check out.
Watch it happen
Long-term keys vs temporary credentials
Access keys (AKIA...)
- Valid until someone deactivates or deletes them
- Often end up in code, .env files or old laptops
- Leaked keys are hunted by automated bots
- Must be rotated manually
Temporary credentials (ASIA...)
- Issued by roles, Identity Center or STS
- Expire automatically after minutes or hours
- Nothing permanent to leak in code
- Refreshed for you by the CLI and SDKs
Use roles for EC2, Lambda and CI pipelines, and Identity Center for people. Keep long-term keys only where nothing else works.
The big ideas
What you need to know
Roles for AWS compute
An EC2 instance profile or Lambda execution role gives the code credentials automatically. No keys in config files.
OIDC for CI
GitHub Actions can assume an IAM role through OpenID Connect, so no AWS keys are stored as repo secrets.
Rotate and remove
An IAM user can have two keys, which lets you rotate without downtime. Delete keys that haven't been used in months.
If a key leaks
Deactivate it immediately, check CloudTrail for what it did, delete it, and clean up anything it created.
See it in code
Walk through the code
1# See every key for a user and when each was last used2aws iam list-access-keys --user-name build-bot3aws iam get-access-key-last-used --access-key-id AKIAEXAMPLEKEY1234564 5# Rotate: create the new key, update the app, then retire the old one6aws iam create-access-key --user-name build-bot7aws iam update-access-key --user-name build-bot \8 --access-key-id AKIAEXAMPLEKEY123456 --status Inactive9aws iam delete-access-key --user-name build-bot \10 --access-key-id AKIAEXAMPLEKEY1234561/4Find old or unused keys. LastUsedDate tells you whether anything still depends on a key.
Safe key rotation for an IAM user that genuinely needs long-term keys. Deactivate first, so you can re-enable if something breaks.
Save yourself the pain
Common mistakes
Oops
Committing a .env file with AWS keys and deleting it in the next commit.
Do this instead
Git history keeps it. Deactivate the key at once and rotate. Add .env to .gitignore and use a secret scanner.
Oops
Creating access keys for an EC2 app to call S3.
Do this instead
Attach an IAM role to the instance. The SDK picks up temporary credentials automatically.
Your mission
Key hygiene audit
Quick check
Your Python app on EC2 needs to read from S3. What is the most secure way to give it credentials?
Go deeper
- 1Check that none of your repositories contain AWS keys, using a tool like git-secrets or gitleaks.
- 2Delete any access keys you are not actively using.
- 3Learn what to do if a key leaks: deactivate it, review CloudTrail and remove unknown resources.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.