Interview Prep/Python for DevOps/boto3 & AWS automation

How does boto3 find credentials?

BeginnerConceptboto3 & AWS automation
Answer

The credential provider chain, in order (simplified):

  1. Explicit parameters to Session/client (avoid).
  2. Environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN.
  3. Web identity token (AWS_WEB_IDENTITY_TOKEN_FILE + AWS_ROLE_ARN), used by IRSA and some CI setups.
  4. Shared credentials file ~/.aws/credentials, then ~/.aws/config profiles (including SSO and role_arn/source_profile assume-role).
  5. Container credentials (ECS task role, EKS Pod Identity via AWS_CONTAINER_CREDENTIALS_FULL_URI).
  6. EC2 instance metadata (IMDSv2) instance profile.

AWS_PROFILE selects the profile. The first source found wins, which is why a stale exported key overrides your SSO profile.

All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation