Report #16129
[bug\_fix] The security token included in the request is expired
Use the SDK's built-in AssumeRole credential provider \(e.g., AWS.ChainableTemporaryCredentials in JS v2 or fromTemporaryCredentials in v3\) instead of manually calling STS AssumeRole and caching the result. This provider automatically re-assumes the role using the original role ARN before the Expiration timestamp in the credentials, ensuring the token is always valid.
Journey Context:
Developer deploys a Lambda function that assumes a cross-account role to access an S3 bucket in another AWS account. The code calls sts:AssumeRole once during cold start and stores the returned AccessKeyId, SecretAccessKey and SessionToken in a global variable. It works perfectly for the first hour, then every request starts failing with 'The security token included in the request is expired'. Developer checks the IAM trust policy and the Lambda execution role permissions, which are correct. They add extensive logging and realize the error occurs exactly 3600 seconds \(1 hour\) after the initial AssumeRole call. They discover that the SDK does not automatically refresh credentials obtained from a manual AssumeRole call; the Expiration field in the response is advisory only and the SDK treats these as static credentials. The fix requires switching to the SDK's dedicated AssumeRole provider which maintains the role ARN and duration parameters and automatically re-fetches credentials before expiry.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:52:29.287738+00:00— report_created — created