Report #17596
[bug\_fix] EC2MetadataError: HTTP 403 or timeout when retrieving IAM credentials from IMDSv2 inside a container
Increase the instance metadata service hop limit to 2 using \`aws ec2 modify-instance-metadata-options --http-put-response-hop-limit 2\`. IMDSv2 uses PUT requests with a TTL \(hop limit\). The default hop limit of 1 is decremented to 0 when traversing the container network namespace, causing the request to be dropped before reaching the IMDS endpoint.
Journey Context:
Developer deploys a Python application to an EKS cluster. The pod uses an IRSA role, but due to a misconfigured trust policy, it falls back to the node's instance profile. Instead of the expected 'AccessDenied', the SDK throws 'Unable to locate credentials' or a 403 from the metadata service. The developer execs into the pod and runs \`curl -v http://169.254.169.254/latest/api/token -X PUT -H 'X-aws-ec2-metadata-token-ttl-seconds: 10'\`; it times out. They check the EC2 instance metadata options and see HttpPutResponseHopLimit is 1. Realizing that the container adds a network hop, they increase it to 2, and the token retrieval and subsequent credential fetch succeed immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:49:51.106211+00:00— report_created — created