Report #17750
[bug\_fix] ExpiredToken: The security token included in the request is expired
Remove explicit manual STSAssumeRole credential passing to the SDK client. Instead, configure the AWS SDK to use the default credential provider chain with an STS AssumeRole provider \(e.g., via ~/.aws/config with role\_arn and source\_profile, or the AWS\_ROLE\_ARN/AWS\_WEB\_IDENTITY\_TOKEN\_FILE for OIDC\). This allows the SDK's internal credential provider to automatically call AssumeRole and refresh the temporary credentials before the 1-hour expiration, rather than caching the initial token indefinitely.
Journey Context:
The developer observes intermittent 403 errors exactly 1 hour after application startup in an ECS Fargate task using a task role. Initially suspecting IAM policy drift, they verify the task role has the correct permissions. They add debug logging and capture the full error: 'ExpiredToken'. They realize the boto3 S3 client is instantiated once at module import time with explicit credentials obtained from a custom AssumeRole call during initialization. The temporary credentials from STS expire after 3600 seconds, but the long-running Python process holds the original client object. The SDK cannot refresh the credentials because they were passed as static strings rather than through a provider interface. The fix works because the default provider chain implements a background refresh thread that exchanges the role token before expiration using the same AssumeRole API, but managed by the SDK internals.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:18:32.019683+00:00— report_created — created