Is it possible to have separate handler for one function but each event type.
For example.
Type: AWS::Serverless::Function
Properties:
FunctionName: ecommerce-lambda
Handler: src/handlers/ecommerceHandler.handler. <--- HERE is one handler for all event type below.
Runtime: nodejs12.x
Description: Products Lambda function.
Policies:
- AWSLambdaBasicExecutionRole
- AmazonDynamoDBFullAccess
Environment:
Variables:
LAMBDA_ENVIRONMENT: local
Events:
# Products
GetProductsAPI: <---- Can this be some other handler?
Type: Api
Properties:
Path: /api/products
Method: GET
PostProductsAPI: <---- Can this be some other handler?
Type: Api
Properties:
Path: /api/products
Method: POST
Given that I dont want to do following.
Resources:
ApiResource:
Type: AWS::Serverless::Api
Properties:
StageName: prod
TimeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: firstsample/firstsample.handler # firstsample.js file is in firstsample direcotory
Role: !GetAtt BasicAWSLambdaRole.Arn
Runtime: nodejs6.10
CodeUri: ./ # Look for code in the same directory as the output SAM file
Events:
MyTimeApi:
Type: Api
Properties:
Path: /TimeResource
Method: GET
RestApiId: !Ref ApiResource
SecondSampleFunction:
Type: AWS::Serverless::Function
Properties:
Handler: secondsample.handler # didn't have to include secondsample directory
Role: !GetAtt BasicAWSLambdaRole.Arn
Runtime: nodejs6.10
CodeUri: ./secondsample # code is in the secondsample directory, located in same directory
Events:
MyTimeApi:
Type: Api
Properties:
Path: /TextResource
Method: GET
RestApiId: !Ref ApiResource
I want the setup where I want to each endpoint to be handle by its own lambda. GET should have its own lambda, POST should have its own lambda.