aws-lambda - 如何使用 @aws-cdk/pipelines 模块构造打包依赖项?出现错误 TS2307
问题描述
我一直在尝试使用新的 AWS CDK 管道构造 ( https://docs.aws.amazon.com/cdk/api/latest/docs/pipelines-readme.html ),并成功设置了几个项目,包括关注此处的博客文章公告:https ://aws.amazon.com/blogs/developer/cdk-pipelines-continuous-delivery-for-aws-cdk-applications/ 。
但是,一旦我尝试向我的 lambdas 添加依赖项,构建就会失败并显示
lib/lambda/handler.ts(2,24): error TS2307: Cannot find module 'stripe' or its corresponding type declarations.
我已经在 lambdas 目录中安装了 package.json 文件和 node_modules,尝试压缩 lambdas 和 node_modules,尝试使用控制台上传 zip 文件,并尝试在“synthAction”步骤中获取“buildCommand”以安装依赖关系。没有任何效果。
该资产似乎是在 cdk.out 目录中创建的,并且正在上传代码更改,但 node_modules 本身从未与 lambda 函数一起打包。
我正在使用“SimpleSynthAction.standardNpmSynth”操作,以及“buildCommand”步骤中的“npm run build”命令。
我查看了Lambda 在使用 CDK 部署时无法从外部文件夹中找到模块,如何在使用 AWS CDK和https://github.com/aws-samples/aws-cdk-examples构建 cdk 时安装 lambda 函数的依赖项/issues/110#issuecomment-550506116没有运气。
我错过了什么?
解决方案
Looks like the issue has to do with bundling. I abandoned the 'all-in on CDK approach' and went back to using a SAM/CDK hybrid, but this new blog post suggests bundling is the answer.
https://aws.amazon.com/blogs/devops/building-apps-with-aws-cdk/
Specifically, it references this construct, which likely would have helped in my situation: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html
Something to try in future.
推荐阅读
- json - python3:json.dump(s) 的行长?
- javascript - 如何使用 javascript/jquery 将大型 html 块附加到刀片文件?
- c# - 我需要包含哪些软件包才能使用 AutomationCore?
- c# - 添加 Outlook 365 日历事件而无需多次登录 C#
- oracle - 在 oracle 11g 中将数据从临时表加载到主表
- c++ - 我的 C++ 语言中的蛮力算法问题
- c# - 在 Web API 中为 Get 控制器设置灵活的模型
- flutter - Flutter Media 查询正文大小
- apache - 如何将 cpprestsdk 与 Apache Web 服务器集成?
- azure - 如何在 Service Fabric 群集上查找特定节点