我的目标
以节点程序(命令行服务器端程序,而不是web应用程序)为例,将其部署为AWS中的lambda函数。
背景:我的节点开发环境/方法
创建lambda函数
- If I try to run my code unchanged (with type: module), it fails as expected, because AWS node is trying to ‘require’ my ES6 module:
- “Must use import to load ES Module: /var/task/index.js\nrequire() of ES modules is not supported. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/task/package.json.”- If I try to change extensions on files to be explicit, AWS gags because it hard-codes the entry point to be ‘index.js’
- If I naively remove the type:module from package.json, it fails as expected because it wants everything to be CommonJS:
- “SyntaxError: Cannot use import statement outside a module",我需要帮助,
从我做过的几个小时的阅读/研究来看,这些似乎是我的选择?
我的问题
谢谢!
发布于 2020-08-29 10:16:02
就我个人而言,我会采用transpile方法。这样,您可以继续以您想要的方式编写代码,并输出lambda满意的内容。
我用TypeScript编写lambda,并编译为lambda兼容的JavaScript (ES2018)。
有各种各样的部署工具-- SAM、Serverless等等--但是看看克拉迪卡,部署选项可以轻松地指定包含入口点的文件和文件中函数的名称。
此外,在向lambda发送数据时,可以使用命令行,这些数据可能来自最终调用lambda的事件。此事件可以包含与命令行参数相同的所有信息。
https://stackoverflow.com/questions/62722387
复制相似问题