Report #40954
[bug\_fix] Unable to locate credentials
Attach an IAM Role \(Instance Profile\) to the EC2 instance using the AWS Console or CLI \(\`aws ec2 associate-iam-instance-profile\`\), ensuring the role's trust policy allows \`ec2.amazonaws.com\`. Alternatively, set environment variables \`AWS\_ACCESS\_KEY\_ID\` and \`AWS\_SECRET\_ACCESS\_KEY\`. Root cause: The AWS SDK credential provider chain checks env vars, shared config files, and finally the EC2 Instance Metadata Service \(IMDS\) at 169.254.169.254; if no IAM Role is attached, IMDS returns 404, and the chain exhausts, throwing this error.
Journey Context:
Developer launches a new EC2 instance and deploys a Python app using Boto3. It works on their laptop \(using \`aws configure\`\) but fails on EC2 with 'Unable to locate credentials'. They SSH in and run \`aws configure\` interactively, but the process hangs or the config is lost on reboot \(they're using an immutable AMI\). They try hardcoding credentials in the code \(temporarily\) and it works, proving network connectivity to AWS is fine. They check the IAM Console and see an IAM Role called 'MyAppRole' exists, but when they describe the EC2 instance, they see no Instance Profile attached. They attach the role via the Console, and the app immediately starts working because the SDK now successfully calls the metadata service at 169.254.169.254/latest/meta-data/iam/security-credentials/MyAppRole to get temporary credentials.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:12:45.443142+00:00— report_created — created