NoCredentialsError ☁️ AWS

AWS: Unable to locate credentials / Could not load credentials from any providers

The AWS CLI/SDK found no credentials in any place it looks — env vars, profile files, SSO cache or an instance/task role.

Seen on: AWS Python Node.js

Meaning

The SDK’s credential chain checks environment variables, ~/.aws/credentials + config profiles, SSO, web identity, then ECS task role and EC2 instance metadata. None produced credentials.

Common causes

  • No aws configure / SSO login on this machine
  • AWS_PROFILE set to a profile that doesn’t exist
  • Running as another user (sudo, cron, systemd) with a different HOME
  • EC2 instance without an IAM role, or IMDSv2 hop limit too low in containers
  • CI job missing OIDC role assumption

⚡ Quick fix

  1. aws sts get-caller-identity to test
  2. aws configure or aws sso login --profile x
  3. Attach an IAM role to the EC2 instance / ECS task / Lambda
  4. For containers on EC2 with IMDSv2, raise the hop limit to 2

Detailed fix by platform

AWS

  1. Debug the credential chain:
    bash
    aws sts get-caller-identity --debug 2>&1 | grep -i -E 'credential|profile' | head
    env | grep ^AWS_
    aws configure list

How to diagnose

  1. Where — Laptop, CI, EC2, container, Lambda?
  2. Chain — Which providers did the SDK try?
  3. User — Which OS user/HOME runs the process?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.