问题描述
我正在使用 webpack 和无服务器部署到 aws lambda。到目前为止,我已经能够将它配置为将所有依赖项捆绑到一个 ts 文件中,但是 aws 抱怨没有 package.json。所以,我找到了一种上传节点模块文件夹的方法,它也引入了 package.json 但由于我在 Windows 上,aws 实例不喜欢这些库。
如何在运行无服务器包或部署命令时包含 package.json 以便 aws lambda 可以运行安装?
include:
- package.json
不起作用。
解决方法
如果您使用的是 Serverless Webpack 插件,您应该能够通过使用插件的 packagerOptions
配置并指定 x64 架构的 linux 平台以及要打包的 npm 模块列表。
有关详细信息,请参阅插件文档的 Custom scripts 部分。
例如,如果您的 Lambda 函数依赖于 sharp
npm 包,则您需要在 serverless.yml
文件中添加如下内容:
custom:
webpack:
includeModules: true
packagerOptions:
scripts:
- npm_config_platform=linux npm_config_arch=x64 yarn add sharp