Interview Prep/Python for DevOps/boto3, HTTP & API errors

`botocore.exceptions.NoCredentialsError: Unable to locate credentials`

BeginnerTroubleshootingboto3, HTTP & API errors
Answer

Likely causes → No source in the credential chain: no env vars, no ~/.aws profile for this user, no instance/pod role, or IMDS unreachable (hop limit in containers, IMDSv2-only).

Diagnose →

aws sts get-caller-identity
env | grep ^AWS_; ls -la ~/.aws
curl -s -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60"

Fix → Configure the right source: aws sso login --profile x + AWS_PROFILE, attach an instance profile, configure OIDC in CI, IRSA/Pod Identity in EKS. For containers on EC2 using IMDS, raise the metadata hop limit to 2.

Prevent → Document the expected credential source; check get_caller_identity() at startup and log the ARN.

All Python for DevOps questions Roadmap: Python for automation

More on boto3, HTTP & API errors