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

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?ResolutionAn "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 listIf 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            Noneaccess_key             ****************ABCD      config_file    ~/.aws/configsecret_key             ****************ABCD      config_file    ~/.aws/configregion                 us-west-2                 env            AWS_DEFAULT_REGIONIf 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            Noneaccess_key             ****************N36N      env    secret_key             ****************cxxy      env    region                 <not set>                 None            NoneIf 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               Noneaccess_key             ****************YVEQ      iam-rolesecret_key             ****************2a9N      iam-roleregion                 <not set>                 None               NoneIf the command returns the following output, then no credentials are set:Name                    Value             Type                Location----                    -----             ----                --------profile                <not set>          None                Noneaccess_key             <not set>          None                Nonesecret_key             <not set>          None                Noneregion                 <not set>          None                NoneReview 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 informationConfiguration and credential file settings