admin 管理员组

文章数量: 887021

@aws

我在 lambda 上使用 sts 客户端时遇到问题。 当前代码在两天前工作。

const {
  STSClient,
  AssumeRoleCommand,
} = require('@aws-sdk/client-sts')

const stsClient = new STSClient({
  region: process.env.REGION || 'eu-west-1',
})

const params = new AssumeRoleCommand({
  RoleArn: process.env.MARKETPLACE_RESOLVE_CUSTOMER_ROLE_ARN,
  RoleSessionName: `${
    process.env.AWS_LAMBDA_FUNCTION_NAME
  }-${new Date().getTime()}`,
})

const assumedRoleOutput = await stsClient.send(params)

现在它总是抛出如下异常:

2023-02-08T08:07:18.684Z    1a7dd68d-da00-4b07-935c-2f6bc95f996f    ERROR   TypeError: (0 , smithy_client_1.parseRfc3339DateTimeWithOffset) is not a function
 at deserializeAws_queryCredentials (/opt/nodejs/node_modules/@aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:860:117)
 at deserializeAws_queryAssumeRoleResponse (/opt/nodejs/node_modules/@aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:756:32)
 at deserializeAws_queryAssumeRoleCommand (/opt/nodejs/node_modules/@aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:119:16)
 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
 at async /opt/nodejs/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
 at async /opt/nodejs/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
 at async StandardRetryStrategy.retry (/opt/nodejs/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
 at async /opt/nodejs/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:5:22
 at async getMarketplaceResolveCustomerRoleCredentials (/var/task/utils/marketplaceUtils.js:27:29)
 at async Object.resolveMarketplaceCustomer (/var/task/utils/marketplaceUtils.js:50:5) {
'$metadata': { attempts: 1, totalRetryDelay: 0 }

我已经在 3.266.0 和 3.224.0 版本的@aws-sdk/client-sts 上试过了

回答如下:

问题是在创建图层时安装了不正确的aws-sdk版本。 我使用 docker 文件安装我的 lambdas 使用的所有依赖项,并使用如下命令:

RUN npm i @aws-sdk/[email protected]
RUN npm i @aws-sdk/[email protected]

所以 sdk 版本之间可能存在不一致?

所以我尝试创建层而不包括 aws sdk 模块(手动删除)并且它有效(sdk 包含在 lambda 执行环境中)

但是我遇到了另一个错误

aws-sdk/client-marketplace-entitlement-service
之前修复的地方 git issue

所以我更改了 Dockerfile 上的命令以安装我想要的最新主要版本,如下所示:

RUN npm i @aws-sdk/client-sts@3
RUN npm i @aws-sdk/client-marketplace-entitlement-service@3

现在可以了!

本文标签: aws