`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.
More on boto3, HTTP & API errors
`botocore.exceptions.NoRegionError: You must specify a region.` even though `AWS_REGION` is set.Intermediate`botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.`Beginner`An error occurred (ExpiredToken) when calling the ... operation: The security token included in the request is expired` midway through a long job.Advanced`An error occurred (RequestLimitExceeded) when calling the DescribeInstances operation (reached max retries: 4): Request limit exceeded.`Intermediate`An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.`Beginner`An error occurred (SignatureDoesNotMatch)` or `RequestTimeTooSkewed` from AWS.Intermediate