【发布时间】:2023-01-02 21:46:51
【问题描述】:
问题:
在开发我的代码管道时,我遇到了一个新错误,我没有在 CLI 中收到 cdk deploy --all。所有堆栈部署成功。
代码构建错误消息:
src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/index.ts(3,75): error TS2307: Cannot find module '@aws-sdk/client-sfn' or its corresponding type declarations.
Lambda 函数导入语句:
import { SFNClient, SendTaskSuccessCommand, SendTaskFailureCommand } from "@aws-sdk/client-sfn";
Lambda 函数包.json:
{
"name": "intomagentoqueueconsumer",
"module": "commonjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@aws-sdk/client-sfn": "^3.226.0",
"axios": "^1.2.1",
"axios-retry": "^3.3.1"
}
}
Lambda 函数 CDK 定义:
this.intoMagentoQueueConsumer = new NodejsFunction(this, `intoMagentoQueueConsumer`, {
runtime: Runtime.NODEJS_16_X,
handler: "handler",
depsLockFilePath: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/package-lock.json"),
entry: join(__dirname, "../../src/lambda-handlers/queue-consumers/intoMagentoQueueConsumer/index.ts"),
bundling: { minify: false, nodeModules: ["@aws-sdk/client-sfn", "axios", "axios-retry"], externalModules: ["aws-sdk", "crypto-js"] },
});
【问题讨论】:
-
@fedonev,我认为解决方案是“确保我的 npm 版本与代码构建版本相同。为此,我将
installCommands: ["npm i -g npm@latest"]放在我的new ShellStep中。我仍然有问题。 -
在
cdk synth命令运行之前,您是否已确认您已经安装了这些软件包? -
@fedonev,我的想法是没有为每个 Lambda 函数或层安装 node_modules。我现在正在查看 NodejsFunction 捆绑选项。您建议如何验证它们是否已安装?
-
我了解到您的项目有多个
package.json。在您的管道ShellStep命令中,确保您正在为每个命令运行npm ci以安装依赖项。
标签: aws-cdk aws-codebuild