简体   繁体   English

AWS CloudFormation Lambda 模块分享

[英]AWS CloudFormation Lambda module sharing

I want to develop two serverless lambda functions that share some common module.我想开发两个共享一些通用模块的无服务器 lambda 功能。 How can I describe this in the CloudFormation template?如何在 CloudFormation 模板中描述这一点?

desired folders structure:所需的文件夹结构:

src/
    lambda1
    lambda2
    module

desired template syntax:所需的模板语法:

Type: AWS::Serverless::Function
Properties:
    CodeUri: ./src/lambda1

this syntax doesn't include the module code into the deployment of the lambda and therefore I get a Runtime.ImportModuleError:此语法不包括模块代码到 lambda 的部署中,因此我得到一个Runtime.ImportModuleError:

Other discarded options are:其他丢弃的选项是:

option.1选项1

Properties:
    CodeUri: ./src/

but this includes the code of both lambda1 and lambda2 into the deployment of lambda1但这将 lambda1 和 lambda2 的代码都包含在 lambda1 的部署中

option.2选项.2

duplicate the folder of module into both lambda1 and lambda2, but this duplicates the code将模块的文件夹复制到 lambda1 和 lambda2 中,但这会复制代码

What is best approach to achieve this?实现这一目标的最佳方法是什么?

What is best approach to achieve this?实现这一目标的最佳方法是什么?

Use lambda layers .使用 lambda In CloudFomration this is AWS::Lambda::LayerVersion .在 CloudFomration 中,这是AWS::Lambda::LayerVersion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM