Fix Claude Code "AWS credentials expired or invalid"
Claude Code AWS credentials expired or invalid means an expired AWS token. Refresh the credential you use (SSO or keys), then run aws sts get-caller-identity.
AWS credentials expired or invalid · run /login and select "Claude Platform on AWS · refresh credentials", or run `aws sso login --profile myprofile` in another terminal · API Error: 401 ...Your AWS session token expired or was rejected, and the fix is to refresh the credential you actually use: run the command the hint in the middle names if there is one, run aws sso login --profile <profile> in another terminal for an SSO profile, or replace an access key, API key or proxy token, then send the message again. The hint in the middle varies with your setup; only the leading AWS credentials expired or invalid is stable.
[1] Use the leading words to tell three cases apart. The names are similar but the causes are not.
| Starts with | When | Meaning |
|---|---|---|
AWS credentials expired or invalid | A 401 from Claude Platform on AWS or the Bedrock Mantle endpoint | Expired or rejected token. Refreshing the credential you use fixes it |
AWS authentication failed | A 403 from AWS, or a 401 from Amazon Bedrock | Could be expiry, or an IAM or model-access denial. Claude Code cannot tell which |
API Error: Could not load AWS credentials · … | The credential chain on this machine found nothing | No request reached AWS. A sign-in or profile problem |
Plain Amazon Bedrock (the Invoke API) reports an expired token as a 403, not a 401, so Bedrock-only users often get the second line instead.
[2] Read the hint in the middle first. If it says your credentials are managed by this environment (the app that launched Claude Code), that app owns the credential and the steps below do not apply. Retry, or ask your administrator.
[3] Identify the credential you actually use and refresh that one.
| Setup | What to do |
|---|---|
awsAuthRefresh is set | Run the command named in the message (such as aws sso login --profile myprofile) in another terminal and finish the browser sign-in |
SSO profile (AWS_PROFILE, an sso entry in ~/.aws/config) | Run aws sso login as below |
Access key and secret (environment variables, ~/.aws/credentials) | Replace the expired or revoked key with a new one |
Bedrock API key (AWS_BEARER_TOKEN_BEDROCK) | Get and set a new key. With this variable set, Claude Code ignores other AWS credentials, so an SSO sign-in changes nothing |
| Proxy or gateway token | Get a new token from whatever issues it |
For an SSO profile, sign in again from another terminal. Use the profile named in the message, or the value of AWS_PROFILE.
$ aws sso login --profile myprofileFinish the browser sign-in, return to Claude Code and send the message again. Claude Code keeps resolved credentials in memory until five minutes before they expire, but a credential error from the API clears that cache and the retry reads fresh ones, so no restart is needed. With AWS Management Console sign-in (aws login, AWS CLI 2.32.0 or later), a session lasts up to 12 hours.
[4] If the same error returns after the refresh, check the identity outside Claude Code with the same shell and profile.
$ AWS_PROFILE=myprofile aws sts get-caller-identityAn account and ARN in the output mean the credentials are alive. If this fails too, the problem is on the AWS side (profile configuration or SSO session). If it works here but fails only in the VS Code or JetBrains extension, the IDE process did not inherit your shell environment; set AWS_PROFILE and friends in the IDE's settings, or launch the IDE from a terminal that has them exported.
[5] To stop signing in to an SSO profile by hand on every expiry, set awsAuthRefresh. When Claude Code detects expired credentials it runs this command and retries the request.
{"awsAuthRefresh": "aws sso login --profile myprofile", "env": { "AWS_PROFILE": "myprofile" }}The command's output is shown but it cannot take interactive input, so it suits SSO flows you finish in a browser with a URL or code. Claude Code first calls STS GetCallerIdentity to confirm the credentials really expired. With this set, an interactive session can also run the same command without a restart: /login, then 3rd-party platform, then Claude Platform on AWS · refresh credentials.
[6] If AWS authentication failed persists after signing in again, look at permissions. Check in the Amazon Bedrock console that the identity has the IAM policy from the official docs and that the selected model is enabled for that account and region. When the 403 is a missing model access, the hint in the message changes to tell you to enable the model in the console.
[7] Could not load AWS credentials · AWS default-chain credential resolve timed out means the credential chain did not answer within 60 seconds. Common causes are a credential_process in the profile that waits for input it cannot receive, and a container or VM whose instance metadata service (IMDS) never answers. First check whether aws sts get-caller-identity hangs too; if a wrapper with MFA (such as aws-vault) legitimately needs longer, raise the limit with CLAUDE_CODE_AWS_CHAIN_RESOLVE_TIMEOUT_MS.
For 401 errors with an Anthropic API key or claude.ai sign-in, see Claude Code OAuth token has expired and Claude Code error messages and fixes.