Report #103463
[bug\_fix] AWS CLI fails with 'Unable to locate credentials' or 'Error: SSO token has expired or is invalid' when running commands with an SSO profile.
Run \`aws sso login --profile \` \(or \`aws sso login --sso-session \`\) to refresh the cached IAM Identity Center token. If the browser flow fails, use \`--use-device-code\`. For automated workflows, migrate to a non-interactive credential source such as IAM roles or service-linked credentials instead of SSO user sessions.
Journey Context:
You come back after the weekend, run \`aws s3 ls --profile dev\`, and AWS CLI returns 'Unable to locate credentials. You can also configure your credentials by running "aws configure".' Yesterday the same command worked. You check \`~/.aws/config\` and the profile is still there with \`sso\_session\`, \`sso\_account\_id\`, and \`sso\_role\_name\`. You run \`aws sts get-caller-identity --profile dev\` and get the same error. You suspect the config is broken and re-run \`aws configure sso\`, but nothing changes. Then you notice \`~/.aws/sso/cache/\` contains a JSON file whose \`expiresAt\` field is in the past. The AWS CLI was trying to use the cached SSO access token to request short-lived role credentials, but that token expired, so the credential chain collapsed and the CLI reported it could not locate credentials. Running \`aws sso login --profile dev\` opens the browser, re-authenticates through IAM Identity Center, writes a new token to \`~/.aws/sso/cache/\`, and immediately lets \`aws sts get-caller-identity\` succeed again. The confusing error message happens because the CLI does not say 'your SSO session expired'; it just reports a credential-location failure at the end of the chain.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:26:25.047654+00:00— report_created — created