Skip to content

How to Fix AWS CLI Credentials Not Found

DodaTech 1 min read

In this tutorial, you'll learn about How to Fix AWS CLI Credentials Not Found. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

You run an AWS CLI command and get:

Unable to locate credentials. You can configure credentials by running "aws configure".

Or:

An error occurred (AccessDenied) when calling the ListBuckets operation: Access denied

The AWS CLI cannot find valid credentials. You have not configured access keys, or the keys are stored in the wrong location.

Quick Fix

Step 1: Configure credentials via AWS CLI

aws configure

Enter the prompted values:

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json

Step 2: Verify the configuration

aws sts get-caller-identity

Expected output:

{
    "UserId": "AIDAIOSFODNN7EXAMPLE",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/myuser"
}

Step 3: Use environment variables

export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-east-1

Add these to ~/.bashrc or ~/.zshrc for persistence.

Step 4: Use an IAM role (EC2 only)

If running on EC2, attach an IAM role to the instance:

# No credential configuration needed -- CLI uses instance metadata
aws s3 ls

Alternative Solutions

Use a named profile:

aws configure --profile production
aws s3 ls --profile production

Or set AWS_PROFILE:

export AWS_PROFILE=production

Prevention

  • Store credentials in ~/.aws/credentials instead of environment variables for persistence.
  • Use IAM roles on EC2 instead of long-lived keys.
  • Rotate access keys regularly.
  • Never commit credentials to version control.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro