Bobcares

AWS CLI Unable To Locate Credentials | A Quick Fix

by | Sep 29, 2022

Configure AWS credentials correctly in the AWS CLI to resolve the error “Unable to locate credentials”. As a part of our AWS Support Services, Bobcares provides answers to all Amazon S3 queries.

Error “Unable to locate credentials” while using AWS CLI

The AWS CLI stores sensitive credential information that we specify with AWS configured in a local file named credentials, in a folder named .aws in the home directory. An AWS CLI “Unable to locate credentials” error appears when Amazon S3 can’t find the credentials to authenticate AWS API calls. This usually occurs when:

  1. The AWS credentials are not properly configured in the AWS CLI.
  2. Utilizing an outdated AWS CLI version.

 

aws cli unable to locate credentials

How To Fix The Error “Unable to locate credentials” while using AWS CLI?

In order to fix the error, our Support team suggests confirming the AWS credentials are correctly configured in the AWS CLI. We can use the following command to see if the AWS CLI is set up with credentials:

$ aws configure list

With credentials 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-1 env AWS_DEFAULT_REGION

If credentials are set up using environment variables, the command responds with something like this:

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

The command provides a response that is like the following if the credentials are configured in an instance profile:

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

No credentials are configured If the command returns the following output:

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

To fix the AWS CLI unable to locate credentials error, we have to analyze the response to see whether credentials are missing or incorrect.

How To Set And View Credentials?

We can use the aws configure to set and view the credentials, Region, and output format. For e.g.,

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

The command aws configure set can be used to set any credentials or configuration settings using aws configure set. Specify the profile that we want to view or modify with the –profile setting. For example, the below command sets the region in the profile named bobcares.

aws configure set region us-west-2 --profile bobcares

To remove a setting, use an empty string as the value, or manually delete the setting in the config and credentials files in a text editor.

aws configure set cli_pager "" --profile bobcares

We also have to make sure to use the most recent AWS CLI version to avoid error.

Let’s see a case when one of the users encounters this AWS CLI “unable to locate credentials” error and how our Support team assisted with the issue. While the user uses the shell script to download some files from S3 and mount an EBS drive, he ends up with the message, “Unable to locate credentials”. The code the customer used is as follows:

#!/bin/bash

AWS_CONFIG_FILE="~/.aws/config"

echo $1

sudo mkfs -t ext4 $1
sudo mkdir /s3-backup-test
sudo chmod -R ugo+rw /s3-backup-test
sudo mount $1 /s3-backup-test

sudo aws s3 sync s3://backup-test-s3 /s3-backup/test

du -h /s3-backup-test
ipt (short version):

From reviewing the code, we understand the user runs the script with sudo. However, they specify the credentials as a normal user. Our Support team suggests the user do everything with AWS as root or as a normal user to fix unable to locate credentials in AWS CLI. This happens because sudo will change the $HOME directory to /root, and remove most bash variables like AWS_CONFIG_FILE from the environment.

[Looking for a solution to another query? We are just a click away.]

Conclusion

An “Unable to locate credentials” error indicates that Amazon S3 can’t find the credentials to authenticate AWS API calls. In this article, our Support team explains the method to fix the error efficiently.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

2 Comments

  1. William

    #!/bin/bash

    # Build and push ComfyUI image to ECR

    if [ -z “$1” ]
    then
    echo “Usage: build_and_push.sh ”
    exit 1
    fi

    REGION=$1
    ACCOUNT_ID=$(aws sts get-caller-identity –query Account –output text)
    echo “AccountID: $ACCOUNT_ID, Region: $REGION”

    docker build –platform=”linux/amd64″ . -t comfyui-images
    docker tag comfyui-images:latest ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/comfyui-images:latest
    aws ecr get-login-password –region ${REGION} | docker login –username AWS –password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com
    docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/comfyui-images:latest

    docker images|grep none|awk ‘{print $3}’|xargs -I {} docker rmi -f {}

    Reply
    • Hiba Razak

      Hello,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF