Report #12237
[gotcha] AWS SDK 'Unable to locate credentials' or metadata timeout when running in Docker/ECS/EKS on EC2
Set the IMDSv2 hop limit to 2 \(minimum\) on the EC2 instance metadata options: \`aws ec2 modify-instance-metadata-options --instance-id i-xxx --http-put-response-hop-limit 2\`. Do not disable IMDSv1 as a quick fix without understanding the hop limit requirement.
Journey Context:
IMDSv2 introduced a session-oriented approach where you PUT a token to the metadata service \(169.254.169.254\) with a TTL. By default, the hop limit \(IP TTL\) is set to 1. When running inside a Docker container on EC2, the packet crosses a network namespace boundary, decrementing the TTL. With TTL=1, it becomes 0 and is dropped, so the container cannot reach the metadata service to get IAM credentials. This manifests as 'Unable to locate credentials' errors that are intermittent or only happen in containers. The fix is increasing the hop limit to 2, allowing one 'hop' into the container namespace. This is often missed because people assume IMDSv2 is just a toggle and don't understand the network implications.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:22:40.189908+00:00— report_created — created