AWS CLI "Unable to locate credentials": where the CLI looks, and why it found nothing
Fix AWS CLI "Unable to locate credentials": check the profile and user, environment variables, SSO and aws login, EC2 instance roles, IMDS in containers, and cron jobs.
by OhSudo ··
Checked on real software: AWS CLI 2 · November 2026How we check
$ aws s3 lsaws: [ERROR]: An error occurred (NoCredentials): Unable to locate credentials. You can configure credentials by running "aws login".Older versions of AWS CLI v2 end with by running "aws configure", without the [ERROR] prefix.
The AWS CLI looked for credentials in every place it knows, in order, and found none. It hasn’t contacted AWS yet, so this isn’t about permissions. The question is why none of those places had anything for the user, profile and machine where the command ran.
- Command-line options--profilethen
- Environment variablesAWS_ACCESS_KEY_ID…, AWS_PROFILEthen
- ~/.aws/credentials and configincluding SSO and role profilesthen
- Container credentialsECS tasks, EKS Pod Identitythen
- EC2 instance rolefrom the metadata service(breaks here)
↻ Nothing found in any of them: Unable to locate credentials.
TL;DR
aws configure list # what the CLI found, and whereaws sts get-caller-identity # who you are, once it works
aws login # sign in through the browser (recent CLI versions)aws sso login --profile prod # or log in with IAM Identity Centeraws configure # or set access keys for this user1. See where it looked
aws configure listNAME : VALUE : TYPE : LOCATIONprofile : <not set> : None : Noneaccess_key : <not set> : None : Nonesecret_key : <not set> : None : Noneregion : eu-west-1 : config-file : ~/.aws/configThe CLI checks, in this order:
- command-line options such as
--profile; - environment variables:
AWS_ACCESS_KEY_IDwithAWS_SECRET_ACCESS_KEY(andAWS_SESSION_TOKEN), orAWS_PROFILE; ~/.aws/credentialsand~/.aws/config, including SSO and role profiles;- a container’s credentials (ECS tasks, EKS Pod Identity);
- the EC2 instance’s role, from the instance metadata service (IMDS).
2. Another user, another home folder
Credentials in ~/.aws/ belong to one user:
sudo aws …runs as root and reads/root/.aws/, not yours. Dropsudo, or usesudo -Ecarefully.- cron and systemd run with a minimal environment, often as another user, so environment variables from your shell aren’t there. Use a profile in that user’s
~/.aws/, or the instance role. - Docker: a container has none of the host’s files. Mount them read-only,
-v ~/.aws:/root/.aws:ro, or pass the variables with-e. On AWS, prefer the task or instance role.
3. A named profile
With profiles, the CLI uses default unless told otherwise. If you only have [prod], plain aws s3 ls finds nothing. Choose one:
aws s3 ls --profile prodexport AWS_PROFILE=prodA profile name that doesn’t exist gives another message: The config profile (prod) could not be found.
aws login, in recent versions, signs you in through the browser with the same credentials as the AWS console, and keeps short-lived credentials for the CLI.
For IAM Identity Center (SSO) profiles, run aws sso login --profile prod when the session expires. An expired SSO session usually says so with its own message about the token.
4. On EC2: the instance role
An instance without a role attached has no credentials to give. Check in the EC2 console (Actions → Security → Modify IAM role), or from the instance:
TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60')curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/That prints the role’s name, or nothing when there’s none.
In a container on EC2, the instance has a role and the container still finds nothing: with IMDSv2, the instance answers only as many network hops as HttpPutResponseHopLimit allows. It’s 1 on many instances (newer AMIs, such as Amazon Linux 2023, set 2), and the container’s traffic takes two. Check it with aws ec2 describe-instances --instance-ids i-0abc123 --query 'Reservations[].Instances[].MetadataOptions', and raise it to 2:
aws ec2 modify-instance-metadata-options --instance-id i-0abc123 --http-put-response-hop-limit 2 --http-endpoint enabledOn ECS, use a task role. On EKS, use EKS Pod Identity or IAM roles for service accounts, rather than the node’s role.
5. In CI
Use OpenID Connect so the pipeline gets short-lived credentials without stored keys. In GitHub Actions, aws-actions/configure-aws-credentials with role-to-assume, and permissions: id-token: write in the workflow. A step that runs before it, or in another job, has no credentials.
Warning
Don’t paste access keys into scripts, Dockerfiles, compose.yaml, or a repository. Keys in an image or in Git history leak, and bots look for them on GitHub within minutes. Use roles where AWS offers them, and short-lived credentials everywhere else.
Shell, we have a problem!
Similar, but different: is not authorized to perform means AWS knows who you are, and denies the action. AccessDenied from S3 is the same, for a bucket. InvalidClientTokenId or SignatureDoesNotMatch means credentials were found, and they’re wrong or deleted. ExpiredToken means temporary credentials ran out. On Azure, the same thing is Please run 'az login'. For everyday commands, see the AWS CLI cheat sheet. Credentials found, but too old: ExpiredToken.
Found this useful? Share it.
Found a mistake? Let us know at contact@ohsudo.com.