# Error when retrieving token from sso: Token has expired and refresh failed

AWS error fixes · Updated 16 November 2026

**Short answer:** Your IAM Identity Center sign-in has ended and the CLI could not renew it silently. Run aws sso login --profile <name> (or --sso-session <name>) to sign in again. If it keeps happening every hour, convert the profile to the sso-session format with aws configure sso so the CLI can use refresh tokens.

## What has expired

An SSO profile involves two layers of credentials. The **SSO access token**, cached under `~/.aws/sso/cache/`, proves you signed in to IAM Identity Center. The CLI exchanges it for short-lived **role credentials** whenever it needs them. This error means the access token is past its expiry and the CLI's attempt to refresh it failed, so it can't obtain role credentials either:

```
Error when retrieving token from sso: Token has expired and refresh failed
```

How long you stay signed in is set by your Identity Center administrator's session duration, so it varies between organisations.

## Why the refresh failed

| Cause | Sign |
|---|---|
| The Identity Center session reached its maximum duration | Happens at the same time each day; only a browser sign-in fixes it |
| Legacy profile format (`sso_start_url` directly in the profile) | The legacy format has no refresh token, so it fails as soon as the access token expires |
| Corrupt or stale cache files | `aws sso login` succeeds but the next command still fails |
| Session revoked by an administrator, or your password or MFA changed | Started failing mid-day after a security change |
| Old AWS CLI v2 or SDK that predates sso-session support | `aws --version` is well behind current |

## Fix it

1. **Sign in again** with the profile that failed:

   ```
   aws sso login --profile prod-admin
   aws sts get-caller-identity --profile prod-admin
   ```

   If several profiles share one `[sso-session]`, one login covers them all: `aws sso login --sso-session my-org`.

2. **Move to the sso-session format** if your config looks like the legacy one. Run `aws configure sso` and give the session a name; the result looks like:

   ```
   [profile prod-admin]
   sso_session = my-org
   sso_account_id = 123456789012
   sso_role_name = AdministratorAccess
   region = eu-west-2

   [sso-session my-org]
   sso_start_url = https://my-org.awsapps.com/start
   sso_region = eu-west-2
   sso_registration_scopes = sso:account:access
   ```

3. **Clear the cache** if login appears to work but commands still fail, then log in again:

   ```
   aws sso logout
   rm -f ~/.aws/sso/cache/*.json ~/.aws/cli/cache/*.json
   aws sso login --profile prod-admin
   ```

4. **Update the CLI** if `aws configure sso` doesn't ask for a session name.

## Terraform, SDKs and other tools

Tools using the AWS SDK read the same `~/.aws/sso/cache`, but they cannot open a browser to sign you in. When Terraform or a Python script reports a similar SSO token error, run `aws sso login` in the same user account and rerun the tool with the same `AWS_PROFILE`. Older SDK versions that don't understand `sso_session` may need upgrading, or you can hand them short-lived keys with `aws configure export-credentials --profile prod-admin --format env`.

For headless machines or SSH sessions where a browser can't open, see [SSO login without a browser](https://cloudconsole.dev/how-to/aws-sso-login-without-browser).

## Questions

### How do I renew an AWS CLI SSO token?

Run aws sso login --profile <name>. With the sso-session configuration the CLI also refreshes the token silently until your Identity Center session reaches its maximum length.

### Why does my AWS SSO token expire so often?

Either your profile uses the legacy format without refresh tokens, or your organisation set a short session duration in IAM Identity Center. Switching to sso-session fixes the first; the second is an administrator setting.

### Is this the same as Error loading SSO Token?

No. That error means no cached token exists for the profile at all; this one means a token exists but has expired and could not be refreshed.

## When this happens away from your desk

An expired SSO session is a common snag when you get paged in the evening and your laptop session from the morning is gone. CloudConsole, a phone app for AWS, is built so you can check alarms and logs on your phone while you sign back in.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Configure IAM Identity Center authentication with the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html)
- [AWS IAM Identity Center documentation](https://docs.aws.amazon.com/singlesignon/)

## Related

- [Error loading SSO Token: Token for <profile> does not exist](https://cloudconsole.dev/errors/error-loading-sso-token)
- [aws sso login](https://cloudconsole.dev/cli/sso-login)
- [aws configure sso](https://cloudconsole.dev/cli/configure-sso)
- [How to log in to AWS SSO from the CLI](https://cloudconsole.dev/how-to/aws-sso-login-cli)
- [AWS SSO login without a browser](https://cloudconsole.dev/how-to/aws-sso-login-without-browser)
- [ExpiredToken: The security token included in the request is expired](https://cloudconsole.dev/errors/expiredtoken)

---

Source: https://cloudconsole.dev/errors/sso-token-expired-refresh-failed

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
