- Newest
- Most votes
- Most comments
The AWS CLI follows a specific order of precedence when determining which credentials to use, which can sometimes lead to your configured profile being ignored.
Environment variables have the highest precedence and will override credentials from both the shared credentials file (/.aws/credentials) and the AWS CLI config file (/.aws/config). For example, if you have the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables set, they will take precedence over any profile settings, even if you've specified a profile using the AWS_PROFILE environment variable.
The order of precedence is:
- Command line options (like --profile)
- Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.)
- Shared credentials file (~/.aws/credentials)
- AWS CLI config file (~/.aws/config)
If you're experiencing issues with the CLI using unexpected credentials, check for:
- Environment variables that might be overriding your profile settings
- Stale or expired credentials/session tokens
- Multiple credential sources conflicting with each other
In some cases, users have resolved persistent credential issues by deleting the .aws folder and reconfiguring their profiles. This can help when there might be old session tokens or conflicting configurations causing problems.
If you want to explicitly use a specific profile, you can use the --profile parameter with your AWS CLI commands to ensure the correct profile is used.
Sources
AWS CLI Configuration Variables — AWS CLI 2.27.33 Command Reference
Why doesn't my AWS CLI work? | AWS re:Post
aws sts get-caller-identity lists the root account i am unable to switch to iam user by using AWS CLI | AWS re:Post
Relevant content
asked 5 years ago
asked 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 2 years ago
