Error Codes Wiki

AWS CLI Credentials Not Found — Unable to Locate Credentials Error

Errorcommand

Overview

Fix AWS CLI 'Unable to locate credentials' error when running commands without configured access keys, IAM roles, or environment variables.

Key Details

  • AWS CLI requires credentials (access key ID and secret access key) to authenticate API requests
  • Credentials can come from: environment variables, ~/.aws/credentials file, IAM roles, or SSO
  • The error 'Unable to locate credentials' means none of the credential sources returned valid credentials
  • AWS CLI checks credentials in order: environment variables > credentials file > IAM instance role
  • On EC2 instances, IAM instance profiles provide credentials automatically without configuration

Common Causes

  • AWS CLI not configured — aws configure was never run on this machine
  • Credentials file (~/.aws/credentials) missing, corrupted, or has wrong permissions
  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) not set or expired
  • IAM role not attached to the EC2 instance, Lambda function, or ECS task

Steps

  1. 1Run 'aws configure' and enter your access key ID, secret access key, default region, and output format
  2. 2Verify credentials file exists: cat ~/.aws/credentials — should have [default] profile with keys
  3. 3For EC2: attach an IAM instance profile/role to the instance via AWS Console > EC2 > Actions > Security
  4. 4For temporary credentials: set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables
  5. 5Test configuration: run 'aws sts get-caller-identity' to verify credentials are working

Tags

aws-clicredentialsiamauthenticationaccess-key

More in Command

Frequently Asked Questions

Always prefer IAM roles over access keys. IAM roles provide temporary credentials that rotate automatically. Access keys are long-lived and must be manually rotated. Use roles for EC2, Lambda, ECS, and any AWS service.