aws-cdk: ❗Notice: CDK CLI: "The security token included in the request is invalid" when using user credentials since 2.167.0

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Overview:

In version 2.167.0 CLI commands, including deployments, fail with authentication errors.

This main cause is with authentication configurations that do not use AWS_SESSION_TOKEN, like IAM User credentials. A second cause is related to the location of the region configuration, see https://github.com/aws/aws-cdk/issues/32130

Complete Error Message:

The security token included in the request is invalid

Workaround:

Revert to 2.166.0

Solution:

Upgrade to 2.167.1

Related Issues:

https://github.com/aws/aws-cdk/issues/32130


Original issue

Since version 2.167.0, deployments fail due to the inability to get the AWS account ID. The following error occurs in the verbose output of cdk synthesize/deploy:

[01:50:17] Resolving default credentials
[01:50:17] Looking up default account ID from STS
[01:50:18] Unable to determine the default AWS account (InvalidClientTokenId): The security token included in the request is invalid

This is despite having correct AWS environment variables set (AWS_DEFAULT_REGION, AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID) and aws sts get-caller-identity works correctly.

Rolling back to 2.166.0 with:

npm install -g cdk@2.166.0

resolves the issue and deployments resume as per normal.

Regression Issue

Confirmed Regression.

Last Known Working CDK Version

No response

Expected Behavior

CDK should function correctly and retrieve the account ID via the AWS credentials.

Current Behavior

CDK throws an error stating that it cannot retrieve the account ID due to security token issues.

Reproduction Steps

Upgrade to 2.167.0, use AWS environment variable credentials but don’t specify the account ID, and run cdk synthesize.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.167.0 (build 677e108)

Framework Version

No response

Node.js Version

v22.6.0

OS

Ubuntu 22.04.4 LTS

Language

.NET

Language Version

No response

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 26 (14 by maintainers)

Commits related to this issue

Most upvoted comments

We have deprecated awd-cdk@2.167.0 on npmjs.com while we continue our investigation.

Please note The aws-cdk-lib and other @aws-cdk/* packages are not effected by the deprecation.

I can confirm the same issue happening on GHE instances too. NPM package deprecation is working as expected and our builds are clearing on 2.166.0. Thanks.

Also* affecting us on Bitbucket Pipelines.

There are 2 distinct problems being discussed in this thread. While they are both introduced by switching from SDKv2 to SDKv3 we should make sure to distinguish them.

  • The security token included in the request is invalid: seems to happen in some circumstances on CI machines, where configuration happens entirely through environment variables.
  • Unable to determine AWS region from environment or AWS configuration (profile: "default"), defaulting to 'us-east-1': the region that is present in a credentials file is not picked up.

This issue was originally created for the first issue by @AdamPD. @otbe, I will make a new issue for your error so we can discuss that there.

Edit: new issue here: https://github.com/aws/aws-cdk/issues/32130

@otaviomacedo here is the -vvv output from a cdk diff, which works fine on 2.166.0

[09:08:41] [trace] SdkProvider#resolveEnvironment()
[09:08:41] [trace] SdkProvider#baseCredentialsPartition()
[09:08:41] [trace]   SdkProvider#resolveEnvironment()
[09:08:41] [trace]   SdkProvider#obtainBaseCredentials()
[09:08:41] [trace]     SdkProvider#defaultAccount()
[09:08:41] [trace]     SdkProvider#defaultCredentials()
[09:08:41] [trace]   SDK#currentAccount()
[09:08:41] Retrieved account ID YYYYYYYYYYYY from disk cache
[09:08:41] [trace] SdkProvider#forEnvironment()
[09:08:41] [trace]   SdkProvider#resolveEnvironment()
[09:08:41] [trace]   SdkProvider#obtainBaseCredentials()
[09:08:41] [trace]     SdkProvider#defaultAccount()
[09:08:41] [trace]     SdkProvider#defaultCredentials()
[09:08:41] [trace]   SdkProvider#withAssumedRole()
[09:08:41] Assuming role 'arn:aws:iam::XXXXXXXXXXXX:role/cdk-sbsl-infra-lookup-role-XXXXXXXXXXXX-us-east-1'.
[09:08:42] Assuming role failed: The security token included in the request is invalid
Could not assume role in target account using current credentials (which are for account YYYYYYYYYYYY) The security token included in the request is invalid . Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
[09:08:42] [trace] SdkProvider#resolveEnvironment()
[09:08:42] [trace] SdkProvider#baseCredentialsPartition()
[09:08:42] [trace]   SdkProvider#resolveEnvironment()
[09:08:42] [trace]   SdkProvider#obtainBaseCredentials()
[09:08:42] [trace]     SdkProvider#defaultAccount()
[09:08:42] [trace]     SdkProvider#defaultCredentials()
[09:08:42] [trace]   SDK#currentAccount()
[09:08:42] Retrieved account ID YYYYYYYYYYYY from disk cache
[09:08:42] [trace] SdkProvider#forEnvironment()
[09:08:42] [trace]   SdkProvider#resolveEnvironment()
[09:08:42] [trace]   SdkProvider#obtainBaseCredentials()
[09:08:42] [trace]     SdkProvider#defaultAccount()
[09:08:42] [trace]     SdkProvider#defaultCredentials()
[09:08:42] [trace]   SdkProvider#withAssumedRole()
[09:08:42] Assuming role 'arn:aws:iam::XXXXXXXXXXXX:role/cdk-sbsl-infra-deploy-role-XXXXXXXXXXXX-us-east-1'.
[09:08:43] Assuming role failed: The security token included in the request is invalid
[09:08:43] Reading cached notices from /home/tom/.cdk/cache/notices.json
Could not assume role in target account using current credentials (which are for account YYYYYYYYYYYY) The security token included in the request is invalid . Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
[09:08:43] Error: Could not assume role in target account using current credentials (which are for account YYYYYYYYYYYY) The security token included in the request is invalid . Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
    at SdkProvider.withAssumedRole (/usr/lib/node_modules/aws-cdk/lib/index.js:593:5643098)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SdkProvider.forEnvironment (/usr/lib/node_modules/aws-cdk/lib/index.js:593:5639480)
    at async EnvironmentAccess.cachedSdkForEnvironment (/usr/lib/node_modules/aws-cdk/lib/index.js:647:7329)
    at async EnvironmentAccess.prepareSdk (/usr/lib/node_modules/aws-cdk/lib/index.js:647:6285)
    at async Deployments.readCurrentTemplateWithNestedStacks (/usr/lib/node_modules/aws-cdk/lib/index.js:647:8697)
    at async CdkToolkit.diff (/usr/lib/node_modules/aws-cdk/lib/index.js:647:201596)
    at async exec3 (/usr/lib/node_modules/aws-cdk/lib/index.js:650:18965)

It’s affecting our Azure cdk deploy pipelines too.