Terraform cannot validate its AWS credentials (sts:GetCallerIdentity fails)
Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentityShort answer
This error means the AWS provider found no working credentials, or found the wrong ones. It checks them with an STS call before anything else. Ask the AWS CLI who you are with the same environment. Then look for stale environment variables, the wrong profile, a missing session token, or a region that is not set.
Fix it fast
1Find out which cause you have
Run the call Terraform makes, in the same shell and with the same environment. If it fails here, the problem is your credentials, not your Terraform code.
aws sts get-caller-identity2Match what you see, then jump to its fix
- 1
get-caller-identity returns an account or user you did not expect, or an expired-token error, although your ~/.aws files are correctOld environment variables override the profile you meant to useFix - 2
The identity call fails with no credentials, or a profile-not-found messageThe profile name is wrong or not selectedFix - 3
The call fails even though the access key and secret look right; the keys come from an assumed role or a single sign-on loginTemporary credentials are used without their session tokenFix - 4
No region appears in the environment, the profile or the provider blockNo region is set anywhereFix
- 1
What does the error look like?
Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity
Cause 1 of 4
Old environment variables override the profile you meant to use
1Check
The provider reads credentials in a fixed order: provider block arguments, then environment variables, then the shared credentials file. A leftover AWS_ACCESS_KEY_ID in the shell therefore beats your profile.
env | grep '^AWS_'2Fix
Unset the variables you do not want, so the next source in the order is used.
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN3Verify
Ask AWS who you are again, then run a plan.
aws sts get-caller-identity
terraform planConfirmed by registry.terraform.io
Cause 2 of 4
The profile name is wrong or not selected
1Check
Without a profile, the provider uses [default]. If your keys live under another profile name, it has to be selected with the profile argument or the AWS_PROFILE variable.
aws configure list-profiles
echo "$AWS_PROFILE"2Fix
Select the profile for this shell, or set it in the provider block.
export AWS_PROFILE=my-profile
# or in main.tf
provider "aws" {
profile = "my-profile"
}3Verify
The identity call now answers with the account you expect.
aws sts get-caller-identity --profile my-profileConfirmed by registry.terraform.io
Cause 3 of 4
Temporary credentials are used without their session token
1Check
Temporary credentials from AWS STS come as three values. The access key and secret alone are not enough: the session token must travel with them, and the CLI's environment variable for it is AWS_SESSION_TOKEN.
env | grep -c '^AWS_SESSION_TOKEN='2Fix
Export all three values together, or switch to a profile that fetches them for you.
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...3Verify
Run the identity call and a plan again.
aws sts get-caller-identity
terraform planConfirmed by docs.aws.amazon.com
Cause 4 of 4
No region is set anywhere
1Check
The region argument is optional in the provider block, but a region must still come from somewhere: the provider block, AWS_REGION or AWS_DEFAULT_REGION, the profile in the shared config file, or instance metadata.
echo "$AWS_REGION $AWS_DEFAULT_REGION"
aws configure get region2Fix
Set it in the provider block so it no longer depends on the machine.
provider "aws" {
region = "us-east-1"
}3Verify
Initialise and plan again.
terraform init
terraform planConfirmed by registry.terraform.io
How do I stop it coming back?
- Pick one credential source per project (a named profile or CI role) and say so in the provider block.
- Do not export long-lived keys in shell startup files; they silently win over profiles.
- In CI, fetch fresh temporary credentials for each run instead of reusing old ones.
- Treat skip_credentials_validation as a test-only switch: it hides the problem, it does not fix it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fixServers
Application Load Balancer returns 504 for requests to EC2 instances
HTTPCode_ELB_504_Count
A 504 from an Application Load Balancer means it could not get an answer from a target in time.
4 causes, each with a fixServers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
aws emr --steps fails: Error parsing parameter, Expected '=', received 'EOF'
Error parsing parameter '--steps': Expected: '=', received: 'EOF' for input:
The AWS CLI tried to read your option as shorthand key=value pairs and ran out of text where it expected an equals sign.
3 causes, each with a fixServers
AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".
The AWS CLI sends every request to one region and has none to use.
4 causes, each with a fixServers
docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY device
Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer.
3 causes, each with a fix