Report #90618
[bug\_fix] AWS EC2 IMDSv2 - Unable to locate credentials or NoCredentialsError on EC2 with IMDSv2 enforced
Upgrade AWS SDK/CLI to versions supporting IMDSv2 \(AWS CLI v1.18.140\+/v2, boto3 >=1.14.0, botocore >=1.17.0\), or modify the EC2 instance metadata options to allow IMDSv1 \(HttpTokens=optional\) if upgrading is not immediately possible. IMDSv2 requires a session token obtained via PUT request which older SDKs do not implement.
Journey Context:
Developer launches a new EC2 instance using a security-hardened AMI or launches with IMDSv2 required \(HttpTokens=required\). IAM Instance Profile is attached with necessary permissions. Developer SSHs in and runs 'aws s3 ls'. Gets 'Unable to locate credentials'. Checks 'curl http://169.254.169.254/latest/meta-data/iam/security-credentials/' and gets 401 Unauthorized. Checks instance metadata service version using 'ec2-metadata -i' or similar. Realizes the instance enforces IMDSv2. Checks AWS CLI version with 'aws --version' and sees 1.16.x or older. Researches and finds that IMDSv2 was introduced to mitigate SSRF attacks and requires a PUT request to get a token before GET requests to the metadata service. Older SDKs only use GET requests \(IMDSv1\). Developer updates AWS CLI to v2 or v1.18.140\+, or updates the Python boto3 library to >=1.14.0. After upgrade, the SDK automatically handles the PUT request for the session token and subsequent credential retrieval succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:41:52.074645+00:00— report_created — created