CloudConsole

The security token included in the request is invalid

Updated 16 November 2026 · How we write and check guides

Short answer

AWS could not match the credentials on your request to a valid identity: the access key ID is unknown, inactive or deleted, or it was sent with a session token that does not belong to it. The usual culprit is a leftover AWS_SESSION_TOKEN environment variable sitting next to newer keys; run aws sts get-caller-identity and aws configure list to see which credentials are really being used.

Most common causes, in order, in 5 steps: 1. A stale AWS_SESSION_TOKEN is exported alongside new long-term keys (or the……
The diagnosis and fix steps from this page, in the order to try them; commands and details are below.

What the error means

This message is returned before any permission check happens. AWS has not decided whether you are allowed to do something; it has failed to work out who you are. Depending on the service, the error code in front of it differs:

An error occurred (UnrecognizedClientException) when calling the GetSecretValue operation: The security token included in the request is invalid.
An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.

SQS, DynamoDB, Lambda and Secrets Manager tend to report UnrecognizedClientException; STS and IAM report InvalidClientTokenId. The fixes are the same, and the HTTP status is 403 in both cases, which is why SQS consumers often log it as "status code 403".

Most common causes, in order

CauseHow to recognise it
A stale AWS_SESSION_TOKEN is exported alongside new long-term keys (or the wrong pair is mixed)aws configure list shows env as the source; keys start with AKIA but a session token is set
Temporary keys (ASIA…) used without their session tokenCopied two values from a console or script and forgot the third
The access key was deleted or deactivatedKey no longer appears in aws iam list-access-keys, or shows Inactive
Calling an opt-in region with a token from the global STS endpoint, or a region not enabled for the accountWorks in us-east-1, fails in a region such as ap-east-1 or me-south-1
Keys from a different partition (AWS China, GovCloud) used against commercial endpointsKeys are valid in their own console but rejected everywhere else

How to fix it

  1. Find out where the credentials come from. The CLI checks command-line options, then environment variables, then the shared files, so an exported variable silently beats your profile.
    aws configure list
    env | grep '^AWS_'
    The Type column says env, shared-credentials-file, sso or iam-role.
  2. Clear leftover variables and try again with the profile you meant to use:
    unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
    aws sts get-caller-identity --profile prod-admin
  3. If the key itself is bad, list the user's keys from a working identity and create a replacement if needed (see rotating IAM access keys):
    aws iam list-access-keys --user-name deploy-bot
  4. For opt-in regions, request credentials from the regional STS endpoint, or change the global endpoint token version to v2 in the IAM account settings so tokens are valid in every region. Also confirm the region is enabled for the account.
  5. In an application, remove hard-coded keys and let the SDK pick up the instance profile, task role or Lambda execution role. Hard-coded credentials are the classic reason a service works on a laptop and fails after deploy.

Specific places it shows up

  • Secrets Manager GetSecretValue in a container: an image that bakes in AWS_ACCESS_KEY_ID from a build stage overrides the ECS task role. Remove the variables from the Dockerfile or task definition.
  • SQS consumers: a long-running worker that loaded keys from a file at start-up keeps using them after someone rotates them. Restart the worker, or better, switch to a role so the SDK refreshes credentials itself.
  • CI pipelines: a secret named AWS_SESSION_TOKEN left over from an old setup is injected into every job. Delete it when you move to OIDC or long-term keys.

Confirm it's fixed

aws sts get-caller-identity needs no permissions, so it is the cleanest test: if it returns an Arn, authentication works and any remaining failure is an authorisation problem with a different message (AccessDenied). If it fails only in one region, the problem is regional STS tokens or a disabled region, not the key.

aws sts get-caller-identity --region me-south-1 --query Arn --output text

Questions

What is an invalid security token in AWS?

It means the access key ID, or the key plus session token combination, on a request does not correspond to any current AWS identity. AWS rejects the request before looking at permissions.

Why does GetCallerIdentity say the security token is invalid?

GetCallerIdentity needs no IAM permissions, so this error there always points at the credentials themselves: a deleted or inactive key, a missing or mismatched session token, or a token not valid in the region you called.

Why do I get this from the AWS CLI when my keys look correct?

Usually an environment variable overrides your profile. Run aws configure list to see the source of each value and unset any AWS_ variables you did not intend to use.

CloudConsole access check screen on a phone, for following up on The security token included in the request is invalid away…
When this happens away from your desk

This error tends to surface as a sudden wave of failures from a worker after a key rotation. CloudConsole, a phone app for AWS, is built to show the resulting alarm and the failing log lines on your phone so you can see which service is affected before you reach a laptop.

Did it start after a deploy? What changed? on the app’s alarm screen lists the deploys and configuration changes from the hour before the alarm fired.

About the app → · Download on the App Store

Sources