Skip to content

AWS CDK Deployment Failing Due to Expired STS Token – How to Extend Session Duration?

0

Hey everyone,

I’m facing an issue with AWS CDK deployment through Jenkins. We’re deploying a complex AWS infrastructure, and the pipeline is quite heavy, taking around 1 hour and 25 minutes to complete.

The problem is that we get the following error:

Error occurred while monitoring stack: ExpiredToken: The security token included in the request is expired

This happens because the temporary credentials generated via assume-role in CDK expire before the deployment finishes. Since STS tokens typically last 1 hour, our deployment exceeds this limit, causing it to fail.

We are already planning to refactor the stack into multiple smaller stacks to reduce deployment time, but in the meantime, we need a way to extend the session duration for CDK to ensure the deployment completes successfully.

Has anyone encountered this issue before? What’s the best approach to increase the session duration for CDK during deployment?

Thanks in advance!

1 Answer
0

If you are using AWS CLI profile, you can set time in the profile as shown below.

[profile my-profile]
role_arn = arn:aws:iam::123456789012:role/MyRole
source_profile = default
**duration_seconds **= 43200

Refer: https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html

If you are using an IAM role, you can set the **MaxSessionDuration **property. CloudFormation reference: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-maxsessionduration

EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.