Report #68448
[bug\_fix] ExpiredToken: The provided token has expired \(from STS AssumeRole\)
Use the SDK's built-in credential provider that handles automatic refresh \(e.g., \`sts:AssumeRoleProvider\` in boto3 configured via \`~/.aws/config\` or \`AssumeRoleCredentialsProvider\` in Java v2\) instead of manually caching the returned credentials. Alternatively, increase \`DurationSeconds\` in the \`assume\_role\` call up to the role's maximum \(default 1 hour, max 12/36 hours\). Root cause: \`sts:AssumeRole\` returns temporary credentials \(\`AccessKeyId\`, \`SecretAccessKey\`, \`SessionToken\`\) valid only for the specified \`DurationSeconds\` \(default 3600s\). If the application stores these in a singleton or environment variable at startup without refresh logic, they expire, causing this error.
Journey Context:
Developer builds a Python data pipeline using boto3 that runs on an EC2 instance for 4 hours. At startup, the code calls \`sts.assume\_role\` to assume a cross-account role for S3 access, then manually sets \`os.environ\['AWS\_ACCESS\_KEY\_ID'\]\`, etc., with the returned credentials. The app runs fine for exactly 1 hour, then all S3 calls fail with \`ClientError: ExpiredToken\`. Developer checks the IAM role's 'Maximum session duration' \(set to 12 hours\) and is confused why it expired at 1 hour. They examine the \`assume\_role\` call and realize they didn't specify \`DurationSeconds\`, so it defaulted to 3600. They consider hardcoding \`DurationSeconds=14400\` \(4 hours\) as a fix, but realize that's brittle. They investigate the SDK source and discover that \`boto3\` has an \`AssumeRoleProvider\` that can be configured in \`~/.aws/config\` with \`role\_arn\` and \`source\_profile\`. When using this provider, the SDK automatically re-calls \`sts:AssumeRole\` and refreshes the credentials in the background before they expire. The developer removes the manual STS call from their Python code, switches to the config-based provider, and the pipeline runs for 4 hours without interruption because the SDK handles the refresh transparently.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:22:35.489979+00:00— report_created — created