How can I fix the error "Unable to locate credentials" when I try to connect to my Amazon S3 bucket using the AWS CLI?

2 minute read
2

When I try to access my Amazon Simple Storage Service (Amazon S3) bucket using the AWS Command Line Interface (AWS CLI), I get an error. How do I fix this?

Resolution

An "Unable to locate credentials" error indicates that Amazon S3 can't find the credentials to authenticate AWS API calls. To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI.

Note: If you still receive an error when running an AWS CLI command, make sure that you’re using the most recent AWS CLI version.

To check if the AWS CLI is configured with credentials, run this command:

$ aws configure list

If your credentials are configured in the config file, the command returns a response similar to the following:

Name                    Value                    Type            Location
----                    -----                    ----            --------
profile                <not set>                 None            None
access_key             ****************ABCD      config_file    ~/.aws/config
secret_key             ****************ABCD      config_file    ~/.aws/config
region                 us-west-2                 env            AWS_DEFAULT_REGION

If your credentials are configured using environment variables, then the command returns a response similar to the following:

Name                   Value                     Type            Location
----                   -----                     ----            --------
profile                <not set>                 None            None
access_key             ****************N36N      env    
secret_key             ****************cxxy      env    
region                 <not set>                 None            None

If your credentials are configured in an instance profile, the command returns a response similar to the following:

Name                    Value                    Type              Location
----                    -----                    ----              --------
profile                <not set>                 None               None
access_key             ****************YVEQ      iam-role
secret_key             ****************2a9N      iam-role
region                 <not set>                 None               None

If the command returns the following output, then no credentials are set:

Name                    Value             Type                Location
----                    -----             ----                --------
profile                <not set>          None                None
access_key             <not set>          None                None
secret_key             <not set>          None                None
region                 <not set>          None                None

Review the response to check whether credentials are missing or the stored credentials are incorrect. To update your credentials, use the AWS CLI, environment variables, or attach an instance profile to an EC2 instance.

After you update your credentials, test the AWS CLI by running an Amazon S3 AWS CLI command, such as aws s3 ls.


Related information

Configuration and credential file settings

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago
2 Comments

You can check the credentials chain to see where aws is looking for the credentials. https://blog.leapp.cloud/aws-sdk-unable-to-locate-credentials

profile picture
replied a year ago

Thank you!!!!!!!

Hadlich
replied 3 months ago