There are pros and cons to using lambda functions as your AppsSync resolvers (although note you'll still need to invoke your lambdas from VTLs):
Pros
- Easier to write and maintain
- More powerful for marshalling and validating requests and responses
- Common functionality can be more DRY than possible with VTLs (macros are not supported)
- More flexible debugging and logging
- Easier to test
- Better tooling and linting available
- If you need to support
long
integers in your DynamoDB table (DynamoDB number types do support long
, but AppSync resolvers only support 32-bit integers. You can get around this if you use a lambda, for example by serializing longs to a string before transport through the AppSync resolver layer) - See (currently) open Feature Request: https://github.com/aws/aws-appsync-community/issues/21
Cons
- Extra latency for every invocation
- Cold starts = even more latency (although this can usually be minimised by keeping your lambdas warm if this is a problem for your use case)
- Extra cost
- Extra resources for each lambda, eating up the fixed 200 limit
If you're doing a simple vanilla DynamoDB operation it's worth giving VTLs a go. The docs from AWS are pretty good for this: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html
If you're doing anything mildly complex, such as marshalling fields, looping, or generally hacky non-DRY code, then lambdas are definitely worth considering for the speed of writing and maintaining your code provided you're comfortable with the extra latency and cost.