Temporary credentials are short-lived AWS security credentials issued by the AWS Security Token Service (STS). They consist of an access key ID, a secret access key, and a session token, and they expire automatically after a configurable duration.
Unlike long-term access keys, temporary credentials cannot be leaked permanently: even if stolen, they expire. This is why AWS recommends using IAM roles (which use temporary credentials) instead of IAM users with long-term access keys for every use case possible.
Every set of temporary credentials comes from one of the STS API operations, and each has its own duration rules:
The session token is the piece that distinguishes temporary credentials from long-term keys. AWS validates it on every request, and its size is not fixed, so never assume a maximum length when storing it.
The classic failure pattern is credential exfiltration through the EC2 instance metadata service. An application running on an instance with an attached IAM role fetches its temporary credentials from the metadata endpoint. If that application has a server-side request forgery (SSRF) flaw and the instance still allows IMDSv1, an attacker can request the metadata URL through the vulnerable app, read the role credentials, and replay them from their own machine. The credentials are temporary, but a window of several hours is plenty of time to enumerate S3 buckets or spin up compute.
Two lessons follow. First, expiry limits damage, it does not prevent it: pair short sessions with detection and least-privilege role policies. Second, enforce IMDSv2 on your instances so that metadata requests require a session-oriented token, which blocks the simple SSRF pattern. Also remember that shortening session duration is a real control: a 15 minute session stolen in transit is worth far less to an attacker than a 12 hour one.
You can see the mechanics yourself by requesting a short session token for an IAM user with MFA:
aws sts get-session-token --duration-seconds 900 --serial-number arn:aws:iam::123456789012:mfa/my-user --token-code 123456
The response contains AccessKeyId, SecretAccessKey, SessionToken, and an Expiration timestamp. Export all three values as environment variables and every subsequent CLI call runs under the temporary session. When the expiration passes, the same calls start failing with an expired token error, no revocation step needed.
How long do temporary credentials last?
It depends on the API. GetSessionToken defaults to 12 hours and can run from 15 minutes to 36 hours for IAM users. Root user session tokens are capped at one hour. Role sessions obtained through AssumeRole respect the maximum session duration configured on the role itself, and SAML sessions default to one hour unless a longer duration is requested.
Can I revoke temporary credentials before they expire?
You cannot invalidate an issued session token directly. What you can do is change what the session is allowed to do: IAM evaluates the role's permissions policies on every request, so removing permissions from the role, or adding an explicit deny, takes effect immediately for all active sessions using that role.
Do temporary credentials behave differently from long-term keys in API calls?
Almost identically. The only mechanical difference is that requests must include the session token alongside the access key and secret key. AWS SDKs and the CLI handle this automatically, and SDK credential providers refresh sessions before they expire, which is why role-based workloads rarely need to think about it.
The process of obtaining temporary security credentials by calling AWS STS to take on the permissions of an IAM role.
An AWS identity with temporary credentials that can be assumed by users, services, or applications to perform actions without long-term access keys.
A long-term credential pair (access key ID + secret access key) used to authenticate programmatic requests to AWS. Should be replaced with IAM roles wherever possible.
Toc Consulting: AWS Security & Cloud Architecture
Our team helps engineering teams secure and architect AWS the right way: assessment in week one, a prioritized action plan in week two.