# InvalidClientTokenId: The security token included in the request is invalid

AWS error fixes · Updated 16 November 2026

**Short answer:** InvalidClientTokenId means STS or IAM does not recognise the access key ID you signed with, or the session token sent with it. In Terraform it almost always appears during provider start-up, when the provider calls sts:GetCallerIdentity with credentials from an unexpected source; check which credentials Terraform resolves (environment variables beat profiles) and whether the key is still active.

## Where you see it

`InvalidClientTokenId` is the error code STS and IAM use for unrecognised credentials. The Terraform AWS provider validates credentials as soon as it starts, by calling `GetCallerIdentity`, so a bad key stops `plan` before anything is read:

```
Error: configuring Terraform AWS Provider: validating provider credentials:
retrieving caller identity from STS: operation error STS: GetCallerIdentity,
https response error StatusCode: 403, RequestID: 6f0e…,
api error InvalidClientTokenId: The security token included in the request is invalid.
```

The same code appears from the CLI (`aws sts get-caller-identity` and IAM commands) and from EC2 or CloudFormation APIs in some cases. It is an authentication failure, not a missing permission.

## Most common causes

| Cause | Check |
|---|---|
| Environment variables with old keys override the profile you expect Terraform to use | `env \| grep '^AWS_'` in the shell or CI job that runs Terraform |
| The S3 state backend uses different credentials from the provider | Error appears during `terraform init`, not `plan`; the `backend "s3"` block has its own `profile`/role settings |
| Access key deactivated, deleted or just created | New keys can take a few seconds to be accepted everywhere; a deleted key never will |
| Temporary key used without its session token, or with someone else's | Key ID starts with `ASIA` but `AWS_SESSION_TOKEN` is empty or from an earlier session |
| Provider region is an opt-in region and the session token came from the global STS endpoint | Fails only for providers aliased to regions such as `af-south-1` or `ap-east-1` |

## Fix it step by step

1. **Reproduce outside Terraform** using exactly the same environment:

   ```
   aws sts get-caller-identity
   aws configure list
   ```

   If the CLI fails too, the credentials are the problem, not your HCL.

2. **Remove the conflicting source.** Unset stale variables, or point Terraform at a profile explicitly:

   ```
   unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
   export AWS_PROFILE=prod-admin
   terraform plan
   ```

3. **Check the key status** from an identity that works:

   ```
   aws iam list-access-keys --user-name terraform-ci \
     --query 'AccessKeyMetadata[].[AccessKeyId,Status,CreateDate]' --output table
   ```

4. **Fix the backend separately** if `init` fails: give the `backend "s3"` block the same profile or role, then re-run `terraform init -reconfigure`.

5. **Opt-in regions:** set the IAM global endpoint token version to v2 in account settings, or have your role-assumption step use a regional STS endpoint.

## CI-specific gotchas

- A pipeline migrated from stored keys to OIDC role assumption may still inject the old secret variables. Whichever source the SDK finds first wins, and environment variables come first.
- Masked secrets sometimes pick up a trailing newline or space when pasted into a CI settings page. That produces this error for the access key ID, or [SignatureDoesNotMatch](https://cloudconsole.dev/errors/signaturedoesnotmatch) if only the secret is damaged.
- Never set `skip_credentials_validation = true` to make the error go away; the first real API call will fail with the same message, just later and less clearly.

## How this differs from similar errors

`ExpiredToken` means the credentials were valid and have run out; `InvalidClientTokenId` means AWS does not recognise them at all. `InvalidAccessKeyId` is S3's equivalent wording. `AccessDenied` means authentication succeeded and a policy blocked the action, which is a different fix entirely.

## Questions

### Why does Terraform say InvalidClientTokenId when the CLI works?

Terraform is resolving different credentials, usually from environment variables, a different profile, or the S3 backend's own settings. Run Terraform and the CLI from the same shell with AWS_PROFILE set explicitly.

### Can a newly created access key cause InvalidClientTokenId?

Briefly, yes: IAM changes are eventually consistent, so a key used within seconds of creation can be rejected. If the error persists after a minute, the key or its secret is wrong.

### Is InvalidClientTokenId a permissions problem?

No. It is returned before any policy is evaluated. Adding IAM permissions will not fix it; fixing the credentials will.

## When this happens away from your desk

When a pipeline breaks on this error, you usually find out from a failed deploy notification. CloudConsole, a phone app for AWS, is built to show alarms and resource state on your phone, which helps you judge whether the failed deploy left anything half-changed.

[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

- [Troubleshoot IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot.html)
- [Manage AWS STS in an AWS Region](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html)

## Related

- [The security token included in the request is invalid](https://cloudconsole.dev/errors/security-token-included-in-the-request-is-invalid)
- [InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records](https://cloudconsole.dev/errors/s3-invalidaccesskeyid)
- [ExpiredToken: The security token included in the request is expired](https://cloudconsole.dev/errors/expiredtoken)
- [aws sts get-caller-identity](https://cloudconsole.dev/cli/sts-get-caller-identity)
- [aws iam list-access-keys](https://cloudconsole.dev/cli/iam-list-access-keys)
- [How to switch between AWS profiles](https://cloudconsole.dev/how-to/switch-between-aws-profiles)

---

Source: https://cloudconsole.dev/errors/invalidclienttokenid

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