Report #78261
[bug\_fix] AWS 'The security token included in the request is expired' \(STS temporary credentials\)
Refresh the temporary credentials by calling STS AssumeRole again to obtain a new AccessKeyId, SecretAccessKey, and SessionToken. If using AWS CLI profiles with 'role\_arn' configured, run 'aws sts assume-role' or configure 'duration\_seconds' up to the maximum allowed by the IAM role's 'MaxSessionDuration' \(default 3600s, max 43200s\). For EC2/ECS, ensure the metadata service is accessible at 169.254.169.254.
Journey Context:
Developer runs a long-running ETL job on an EC2 instance using boto3 with assumed role credentials exported as environment variables. After exactly one hour, every S3 PUT request fails with 'ExpiredToken: The security token included in the request is expired'. The developer checks the instance metadata service \(IMDS\) at 169.254.169.254 and finds a valid token, realizing they had manually exported temporary credentials from 'aws sts assume-role' at the start of the script instead of letting the SDK automatically retrieve and refresh credentials from the EC2 instance profile. The SDK's default credential provider automatically handles refreshing IMDS credentials, but when hardcoded env vars are present, the SDK uses them without checking expiration until the API call fails. The fix is to remove the hardcoded env vars and rely on the instance profile, or implement a credential provider that refreshes the STS tokens before expiration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:57:27.273562+00:00— report_created — created