Report #8889
[bug\_fix] ExpiredToken: The security token included in the request is expired.
Increase the IAM Role's 'Maximum session duration' setting from the default 1 hour to 12 hours \(or the required duration\), and update the STS AssumeRole API call to request --duration-seconds 43200, because the temporary credentials' TTL is capped by the role's MaxSessionDuration configuration.
Journey Context:
A data engineer runs a nightly ETL job on an on-premise server that uses the AWS CLI to assume a cross-account role for S3 access. The job runs for 3 hours. After 1 hour, all subsequent AWS API calls fail with An error occurred \(ExpiredToken\) when calling the PutObject operation: The provided token has expired. The engineer checks the script and sees it calls aws sts assume-role once at the beginning, exporting the returned AWS\_ACCESS\_KEY\_ID, AWS\_SECRET\_ACCESS\_KEY, and AWS\_SESSION\_TOKEN. They realize the STS temporary credentials expire after 1 hour \(3600 seconds\), which is the default for AssumeRole. They attempt to fix it by adding --duration-seconds 43200 \(12 hours\) to the CLI command, but it fails with MaxSessionDurationExceeded. They check the IAM role in the console and see the 'Maximum session duration' is set to 1 hour. To truly fix it, they have two options: either increase the role's MaxSessionDuration to 12 hours \(if security policy allows\) and update the script to request 12 hours, or implement credential refresh logic in the script using the AWS SDK's assume\_role provider with automatic refresh \(like boto3's RefreshableCredentials or awsume\). They choose to set MaxSessionDuration to 12 hours in the IAM role trust policy and update the script to request 43200 seconds. The job now runs without token expiration because the STS token is valid for the full 3-hour runtime, as the DurationSeconds parameter in the AssumeRole API call successfully requested a TTL within the role's maximum allowed session duration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:44:15.075528+00:00— report_created — created