Sub topic 10
How long a session and its credentials last
This chapter assumes you have configured an sso-session and a profile, and that you can run aws sso login. It explains the two clocks that decide when the CLI asks you to sign in again. Knowing both helps you tell a harmless refresh from a real expiry.
Two layers, two lifetimes
After aws sso login, the CLI holds two different things:
- The access token proves that you signed in. It is tied to your
sso-session. Its lifetime is the session duration set in IAM Identity Center. - The role credentials are the access key, secret key and session token for one account and permission set. The CLI requests them from the token on demand.
The token is the long-lived layer. The role credentials are short-lived and are derived from the token. When the credentials expire, the CLI quietly requests new ones. When the token expires, it cannot, and you must sign in again.
What controls each lifetime
| Layer | Set by | Typical range | On expiry |
|---|---|---|---|
| Access token (the sign-in) | Session duration in IAM Identity Center settings | 15 minutes to 90 days; default 8 hours | Run `aws sso login` again |
| Role credentials | Fixed by the service | About one hour | CLI refreshes them automatically |
| Permission set session duration | The permission set | 1 to 12 hours | Applies to the console and the role session |
Check the current limits in your Identity Center console, because administrators can change them. The session duration is an organization-wide setting. Your own configuration file cannot lengthen it.
Why the token may last longer than you expect
The sso-session block uses sso_registration_scopes = sso:account:access. With this configuration the CLI registers a client and receives a refresh token along with the access token. It uses the refresh token to renew the access token without opening your browser. In practice you sign in once and keep working until the maximum session duration ends, instead of facing a prompt each time the short token lapses.
Profiles written the older way, with sso_start_url and sso_region inside the profile and no sso-session, have no refresh token. They need a new sign-in when the token expires.
Seeing the expiry for yourself
Run a command and then look at the cached files:
aws sts get-caller-identity --profile dev
ls ~/.aws/sso/cache/
grep -h expiresAt ~/.aws/sso/cache/*.jsonEach cache file stores an expiresAt timestamp in UTC. The file holding accessToken shows when your sign-in ends. The credentials the CLI fetches for roles are cached separately in ~/.aws/cli/cache/, and their Expiration field is usually about an hour ahead.
Common mistakes
- Expecting a longer token from the permission set. The permission set duration controls the role session. It does not extend the sign-in token.
- Copying exported credentials and expecting renewal. Values from
aws configure export-credentialsare a snapshot. They stop working at the credentials' expiration, and nothing refreshes them. Export again when they fail. - Mixing up the errors. An expired token usually produces a message such as
Token has expired and refresh failed, or asks you to runaws sso login. Expired role credentials are renewed without a message.
Exercise
You signed in at 09:00 and the session duration is 8 hours. At 11:30 you run a command through a profile that uses an sso-session. Role credentials from 09:00 have expired. Do you need to sign in again, and why?
Show answer
No. The access token is valid until about 17:00, so the CLI uses it to request new role credentials automatically. You would only sign in again after the token's session duration ends, or if the token cannot be refreshed.
Exercise
Which file location holds the sign-in token, and which field tells you when it ends?
Show answer
The token is cached in a JSON file under ~/.aws/sso/cache/, and its expiresAt field gives the expiry time in UTC.