Report #44915
[bug\_fix] botocore.exceptions.ClientError: An error occurred \(ExpiredToken\) when calling the GetObject operation: The provided token has expired
Upgrade \`boto3\` and \`botocore\` to the latest versions to ensure proper automatic credential refresh from the EC2 Instance Metadata Service \(IMDSv2\). Ensure your application does not cache the \`boto3.client\(\)\` or \`Session\` object indefinitely in a global variable that prevents the underlying credential provider from refreshing the temporary credentials before they expire \(typically after 1-6 hours\).
Journey Context:
A data engineer runs a long-running ETL job on an EC2 instance that processes S3 objects for 8 hours using boto3. After 4 hours, the script crashes with ExpiredToken. They check the IAM Role attached to the instance and confirm it has the correct permissions. They realize that IAM Roles provide temporary credentials that expire. They check their boto3 version and see it's 1.9.0 \(very old\). They research and find that older versions of boto3 had bugs with IMDSv2 credential refresh. They upgrade to the latest boto3/botocore. They also refactor their code to create a new client for each batch of processing rather than holding one global client object, ensuring the credential provider chain can refresh the underlying session tokens automatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T05:51:22.274219+00:00— report_created — created