Skip to content

Why does AWS CLI sometimes ignore my configured profile?

0

IAM / CLI Why does AWS CLI sometimes ignore my configured profile? I’ve noticed that even after setting up multiple profiles in ~/.aws/credentials, some AWS CLI commands still use an older or default profile. Is there a specific order of precedence for how the CLI chooses profiles? Could environment variables override the config?

1 Answer
1
Accepted Answer

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:

  1. Command line options (like --profile)
  2. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.)
  3. Shared credentials file (~/.aws/credentials)
  4. 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

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.