"Access keys are safe if I hide them well." They are, until one leaks. An access key doesn't expire on its own, so a key that escapes keeps working for whoever finds it, for months or years, until someone notices and deletes it. Temporary credentials remove that risk by design: they stop working after a short time, whether or not anyone notices the leak.
What an access key is
An access key is a long-term credential for an IAM user (or, which you should never do, the root user). It has two parts:
- an access key ID, which for IAM users starts with
AKIA - a secret access key, shown only once, when you create it
Programs use the pair to sign requests to AWS from the CLI or an SDK. A user can have at most two access keys, which is what makes rotation possible: create the second, switch your application over, then delete the first.
How keys leak
Rarely through anything dramatic. The usual routes are ordinary:
- committed to a code repository, sometimes a public one
- pasted into a chat, a ticket or a wiki page
- left in a credentials file on an old laptop, a build server or a machine image
AWS checks popular public code repositories for exposed keys and, when it finds one, can attach a quarantine policy to the user and open a support case. That's a safety net, not a plan: it only covers places AWS can see, and someone else may find the key first.
What temporary credentials change
Temporary credentials look similar, with one addition and one difference:
- a key ID (it starts with
ASIA) and a secret access key - a session token that must be sent with every request
- an expiry time, typically from minutes to hours
When the time is up, they simply stop working. There is nothing to rotate and nothing to revoke later.
You rarely create them by hand. IAM roles hand them out:
- Servers on EC2 get them through an instance profile.
- Lambda functions and containers get them from their execution or task role.
- People get them by signing in through IAM Identity Center, including for the CLI.
- Systems outside AWS, such as CI/CD pipelines, can exchange their own identity for temporary credentials through federation instead of storing a key.
AWS's own guidance is direct: as a best practice, use temporary credentials instead of creating long-term access keys.
If you really need an access key
Some older tools only accept one. In that case:
- attach a least-privilege policy, scoped to exactly what the tool does
- rotate the key on a schedule
- check last used information in the IAM console and delete keys nobody uses
- never create access keys for the root user
Where AI fits
Automated scanners crawl public code around the clock looking for strings that look like AWS keys, and a leaked key can be abused quickly, often to launch expensive compute. AI raises the odds of a leak in a new way: coding assistants and agents read your files and write code and config at speed, and they can copy a secret from a local file into a commit, a log or a prompt without anyone meaning to.
The defence is the same in both cases. If nothing long-lived is stored on the machine, there is nothing lasting to leak: a temporary credential that escapes is soon worthless. Give your tools and agents roles, not keys.
Quick recap
- Access keys never expire by themselves; a leak lasts until someone finds it.
- Temporary credentials carry a session token and an expiry, and stop working on their own.
- Use roles (and IAM Identity Center for people) instead of stored keys.