Instance role credentials stopped working inside a container on an EC2 host: `Unable to locate credentials`.
IntermediateTroubleshootingIAM and Access Errors
Answer
Likely causes → IMDSv2 hop limit of 1 blocks containers from reaching metadata.
Diagnose →
curl -s -X PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds: 60'
aws ec2 describe-instances --instance-ids i-0abc --query 'Reservations[].Instances[].MetadataOptions'
Fix →
- Set hop limit to 2:
aws ec2 modify-instance-metadata-options --instance-id i-0abc --http-put-response-hop-limit 2 --http-tokens required - Or use task or pod roles
Prevent → Bake hop limit into launch templates.
More on IAM and Access Errors
`An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied` for a user who has S3 read access. What is wrong?Beginner`ExpiredToken: The security token included in the request is expired` in a long CI job. How do you fix it?Beginner`User: arn:aws:sts::111111111111:assumed-role/dev/bob is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::222222222222:role/deploy`. Why?Intermediate`An error occurred (AccessDenied) ... because no identity-based policy allows the s3:GetObject action` yet a bucket policy allows the user. Cross-account?IntermediateIAM policy validation: `MalformedPolicyDocument: Policy document should not specify a principal`. What happened?Intermediate`The security token included in the request is invalid` when using `aws` CLI.Beginner