aws-sdk-js-v3: Behavior of `@aws-sdk/credential-providers` `fromTemporaryCredentials` has changed and results in `InvalidClientTokenId`

Checkboxes for prior research

Describe the bug

When upgrading @aws-sdk/credential-providers from 3.721.0 to 3.742.0, our tests fail when fromTemporaryCredentials is called.

According to credential-providers/CHANGELOG.md, there are changes to fromTemporaryCredentials in 3.731.0 and 3.734.0.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/credential-providers@3.742.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v22.13.1

Reproduction Steps

The relevant code is:

…
const fromTemporaryCredentialsOptions = {
  params: {
    RoleArn: `arn:aws:iam::${id}:role/${rolePathAndName}`,
    // Member must have length less than or equal to 64
    RoleSessionName: roleSessionName,
    DurationSeconds: 1800
  },
  clientConfig: { region, profile }
}
const credentialsProvider = fromTemporaryCredentials(fromTemporaryCredentialsOptions)
const credentials = await credentialsProvider()
return { region, credentials } // awsV3ClientConfig

This is general code, that has the intention to get temporary credentials where the “user” gets necessary permissions by assuming a role (RoleArn). The user‘s credentials should be found in ~/.aws/credentials under the given profile. The returned credentials are then used in different places to create a client to perform commands, e.g.,

const apiGatewayClient = new APIGatewayClient(awsV3ClientConfig)
instance = new S3Client(awsV3ClientConfig)

(but we don’t get there).

Observed Behavior

exception (STSServiceException):
InvalidClientTokenId: The security token included in the request is invalid.
    at throwDefaultError (…/node_modules/@smithy/smithy-client/dist-cjs/index.js:867:20)
    at …/node_modules/@smithy/smithy-client/dist-cjs/index.js:876:5
    at de_CommandError (…/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js:299:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async …/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async …/node_modules/@smithy/core/dist-cjs/index.js:167:18
    at async …/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38
    at async …/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
    at async …/node_modules/@aws-sdk/credential-providers/dist-cjs/fromTemporaryCredentials.base.js:108:33
    at async clientConfig (…/common/awsV3ClientConfig.js:45:27)

Expected Behavior

Return the correct credentials for the role as before.

Possible Solution

No response

Additional Information/Context

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

FYI for anyone following this issue, there is a planned change happening in https://github.com/aws/aws-sdk-js-v3/pull/6982, where when the fromTemporaryCredentials provider is used in a standalone manner (not passed to a client), the region is read from the process.env.AWS_REGION variable or the AWS configuration file.

If the configuration file is used, additionally the AWS_PROFILE variable is consulted when selecting which profile’s region to use.

EDIT: I didn’t even change anything but it started working?. Not sure if this a bug with the SDK or AWS in general somehow.

Hi, I’m not sure if this is the correct issue.

But I seem to be getting the same error when using the SESClient to send emails.

Failed to send verification email: InvalidClientTokenId: The security token included in the request is invalid.
  at throwDefaultError (/usr/src/app/node_modules/.pnpm/@smithy+smithy-client@4.1.3/node_modules/@smithy/smithy-client/dist-cjs/index.js:867:20)
  at /usr/src/app/node_modules/.pnpm/@smithy+smithy-client@4.1.3/node_modules/@smithy/smithy-client/dist-cjs/index.js:876:5
  at de_CommandError (/usr/src/app/node_modules/.pnpm/@aws-sdk+client-ses@3.741.0/node_modules/@aws-sdk/client-ses/dist-cjs/index.js:2935:14)

My service is deployed on ECS. It has task role attached to it for allowing email sending.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Effect": "Allow",
      "Resource": [
        "arn:aws:ses:ap-south-1:438465141267:identity/*"
      ]
    }
  ]
}

I’m not even sure, How I am supposed to debug this, or a workaround for same.