Multiple Lambda functions from the sam.yml file possible?
See original GitHub issueI have a situation where I have multiple lambda functions within our API Gateway’s API. I’m new to AWS and learning as much as I can. I am wondering, how would I change the template yaml (sam.yaml) so that we can deploy to any number of lambda functions and not just one as is the case in this lab. Would you create multiple index.js file per lambda function?
- so index1.js -> will map to first lambda function
- index2.js -> second lambda function;
- etc…
And how do I update the sam.yaml file to reflect this change?
Here’s a snippet code of what I’m trying to accomplish:
Resources:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
PostEvent:
Type: Api
Properties:
Path: /
Method: post
.... and more endpoints here to hit more lambda functions? So do I create multiple index.js to map to each individual lambda function?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:37
Top Results From Across the Web
Multiple Lambda functions from the sam.yml file - Stack Overflow
You can have as many AWS::Serverless::Function resources in a single template as you want as long as they have a unique logical id....
Read more >Automate deployment of nested applications using AWS SAM
A serverless application is a combination of Lambda functions, event sources, and other resources that work together to perform tasks.
Read more >SAM template: Configure an api gateway with multiple lambdas
The above template creates a lambda function ,an API Gateway resource, necessary lambda execution roles, permissions and associates the lambda ...
Read more >Managing Multiple Functions with AWS SAM and Webpack
Copy-pasted webpack files can be tough to handle, with weird ... First of all, I'm going to be exporting two Lambda functions so...
Read more >AWS Lambda Guide - Serverless.yml Reference
Here is a list of all available properties in serverless.yml when the provider ... List of existing Amazon SNS topics in the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as I am aware, you can have multiple JS files, each containing a handler to a different Lambda. The files don’t have to be in the same directory! You can also define the 2nd Lambda function in the same SAM template yaml file where you defined the 1st Lambda function.
Guys,
I have the same question.
Really trying to learn serverless and questions like these - on best practices - is making it super difficult. Would love some direction here.