简体   繁体   English

如何在单个CloudFormation堆栈上创建2个AWS Lambda?

[英]How to create 2 AWS lambdas on a single CloudFormation stack?

I currently have 2 lambda functions, and I'm trying to make a CI/CD process to them. 我目前有2个lambda函数,并且正在尝试对其进行CI / CD处理。 So I have trying with 2 approaches: 所以我尝试了两种方法:

  1. two separate steps on my CI. 在CI上分两个步骤。 I have tried to make CloudFormation package and then deploy each lambda, with each of those having their own SAM template and template. 我尝试制作CloudFormation包,然后部署每个lambda,每个lambda都有自己的SAM模板和模板。 but the result is that the only one that will remain on the stack is the last one deployed. 但是结果是,将唯一保留在堆栈中的是部署的最后一个。 i understand that deploy is an smart way that AWS CLI create to do not use create/update stack actions. 我知道部署是AWS CLI创建的一种不使用创建/更新堆栈操作的明智方式。 but it keeps overwriting between them (yes they have different resource name). 但它们之间会不断覆盖(是的,它们具有不同的资源名称)。

  2. having a single sam template and one step in a single repo: I also attempt this in a single repo having both lambdas and a single sam file, but I have duplicate code on my lambdas the difference is that each of them have different set up for which handler to be used. 具有单个sam模板和单个回购中的一个步骤:我也尝试在具有lambda和单个sam文件的单个回购中进行此操作,但是我的lambda上有重复的代码,不同之处在于它们每个都有不同的设置使用哪个处理程序。

My goal is to have 2 lambdas in a single stack. 我的目标是在单个堆栈中包含2个lambda。

im going to answer my own question because I notice on the sam template was the key. 我要回答我自己的问题,因为我注意到sam模板是关键。 initially i was doing the sam template like this: 最初,我正在像这样做sam模板:

 AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: An AWS Serverless Specification template describing your function. Resources: certainty: Type: 'AWS::Serverless::Function' Properties: Handler: ./myfunc/index.handler Runtime: nodejs8.10 CodeUri: . Description: >- here goes my description MemorySize: 128 Timeout: 20 Role: 'arn:aws:iam::116738426468:role/rolename' Events: Schedule1: Type: Schedule Properties: Schedule: rate(1 day) certaintyauxiliar: Type: 'AWS::Serverless::Function' Properties: Handler: my-other-func/index.handler Runtime: nodejs8.10 CodeUri: . Description: >- blabla blabla. MemorySize: 1152 Timeout: 300 Role: 'arn:aws:iam::116738426468:role/roleanme' Events: Api1: Type: Api Properties: Path: /show-all Method: POST 

what was causing here a "duplicate of the code" was that the lambdas code uri was indicating that should grab all the stuff in the folder that cotained both repos. 这里导致“代码重复”的原因是lambdas代码uri指示应获取包含两个存储库的文件夹中的所有内容。 and telling to go deeper in directories to find the the handler. 并告诉我们更深入的目录以找到处理程序。

so I changed the code uri and the handler and now the lambdas are grabbing just what should be in each lambda. 所以我更改了代码uri和处理程序,现在lambda捕获了每个lambda中应该包含的内容。 now my sam template looks like this: 现在我的sam模板如下所示:

 AWSTemplateFormatVersion: '2010-09-09' Transform: 'AWS::Serverless-2016-10-31' Description: An AWS Serverless Specification template describing your function. Resources: certainty: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler Runtime: nodejs8.10 CodeUri: ./my-func Description: >- here goes my description MemorySize: 128 Timeout: 20 Role: 'arn:aws:iam::116738426468:role/roleName' Events: Schedule1: Type: Schedule Properties: Schedule: rate(1 day) certaintyauxiliar: Type: 'AWS::Serverless::Function' Properties: Handler: index.handler Runtime: nodejs8.10 CodeUri: ./my-other-func Description: >- bla bla bla bla MemorySize: 1152 Timeout: 300 Role: 'arn:aws:iam::116738426468:role/rolename' Events: Api1: Type: Api Properties: Path: /path Method: POST 

sorry, now i can see that at the question I was not providing enough info, but i answer to my own question hoping I can help some as lost as I was. 抱歉,现在我可以看到在这个问题上我没有提供足够的信息,但是我回答了自己的问题,希望我能帮助一些像我一样迷路的人。 Serverless is a nice approach but it does have quiet a learning curves. 无服务器是一种不错的方法,但是它确实具有安静的学习曲线。 Regards, Daniel 问候,丹尼尔

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

相关问题 无法创建 AWS CloudFormation 堆栈 - Unable to create AWS CloudFormation stack 如何在现有堆栈中创建新实例 AWS Cloudformation - How to create a new instance in exsisting stack AWS Cloudformation 如何从AWS CloudFormation模板为特定资源类型创建堆栈 - How to create stack for specific resource types from aws cloudformation template 是否可以在cloudformation中为一组Lambda创建一个AWS :: Lambda :: Version - Is it possible to create an AWS::Lambda::Version for a set of Lambdas in cloudformation 无法通过单个 AWS CloudFormation 堆栈创建 AWS EKS 集群和工作节点组 - Unable to create AWS EKS cluster and worker nodes group by a single AWS CloudFormation stack 如何为特定 CloudFormation 堆栈创建“aws.cloudformation”CloudWatch 事件类型? - How can I create an "aws.cloudformation" CloudWatch event type for a specific CloudFormation stack? AWS Cloudformation 创建堆栈模板错误 - AWS Cloudformation Create-Stack Template Error AWS CloudFormation创建堆栈与部署 - AWS CloudFormation create-stack vs deploy 使用单个 Cloudformation 模板部署 lambdas - Deploy lambdas with single Cloudformation template 如何使用 cloudformation/SAM 创建一个 SQS 队列,该队列与使用 SAM 创建的 lambda 一起使用? - How to create an SQS queue with cloudformation/SAM that works with lambdas created with SAM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM