Explicit flag for direct lambda resolvers
My goal was to avoid VTL request/response templates and go direct lambda. Finally I got an MVP running, thanks for this great plugin! It wasn't clear how to get it working, below solution for anyone else who is looking, and then some thoughts about making it more explicit.
service: mvp2
provider:
name: aws
runtime: nodejs10.x
plugins:
- serverless-appsync-plugin
- serverless-appsync-simulator
- serverless-offline
functions:
hello:
handler: hello.handler
custom:
# APPSYNC
appSync:
authenticationType: API_KEY
dataSources:
- type: AWS_LAMBDA
name: myLambdaSource # data source name
description: 'Lambda DataSource'
config:
functionName: hello
defaultMappingTemplates:
request: false
response: false
mappingTemplates:
- type: Query
dataSource: myLambdaSource
field: getMessage
To my understanding, direct lambda resolver requires the defaultMappingTemplates request/response to be false? Isn't this acting as a global setting like;
appSync:
directLambdaEnabled: true # If set, this causes defaultMappingTemplates to be disabled
...
This would be better as it least to make this explicit. Or even better to apply to each resolver somehow like;
mappingTemplates:
- type: Query
directLambda: true # Default false
dataSource: myLambdaSource
field: getMessage
This could furthermore allow a defaultMappingTemplate to be defined for all other resolvers.
Thanks for the plugin!
@MarcusJones There are 2 ways to use Direct Lambda currently.
-
set
defaultMappingTemplates.requestand/ordefaultMappingTemplates.responseto false. In this case, it will apply to all lambda resolvers that do not specifically declare therequestorresponsemapping templates. -
set
requestand/orresponseto false for specific Lambda resolvers.
mappingTemplates:
- type: Query
request: false
response: false
dataSource: myLambdaSource
field: getMessage
Basically, what specifies if a Lambda resolver is a direct Lambda is if the request and/or response mapping templates are false (as in "don't use mapping template)
Using defaultMappingTemplates is just a global value that allows you to specify a template for ALL resolvers (including non Lambda ones).
Note that Direct Lambda can be enabled separately for the request and response templates (It's not an all or nothing feature).
On a side note, if you are using Lambda to avoid VTL, you might want to have a look at this RFC
Ok great, I had no idea this was an option, and it solves our use case - we want to have a mix of direct lambdas and VTL. Direct lambdas take care of complex cases, and default VTL handles simple DynamoDB access. I submitted #384 with an update to readme. Thanks for RFC link, will follow!