SAM Doctor

ERROR REFERENCE

The security token included in the request is invalid

AWS rejected the credentials outright — not expired, invalid. The access key belongs to no known account (UnrecognizedClientException), or the token was never valid in this partition. Different failure from an expired session, and waiting or refreshing will not fix it.

WHAT IT MEANS

What this error means

The usual causes, in rough order of frequency:

FIX

How to fix it

  1. See which source supplied each credential value (read-only):
    aws configure list
    The Type column exposes the environment-variable override immediately.
  2. Clear the stale environment variables (or set the correct ones) and re-run - in CI, check what an earlier auth step exported into the job environment.
  3. Confirm the account once it works:
    aws sts get-caller-identity
    The account in the output should be the one the stack deploys into.

AUTOMATE THE TRIAGE

Diagnose this automatically

SAM Doctor recognizes the invalid-token wording (high confidence) and keeps it distinct from expired credentials, which have their own rule and fix. Runs locally; no AWS access, no log upload.

python -m pip install sam-doctor
sam-doctor diagnose deployment.log --format markdown

RELATED