DEV Community

loading...

Discussion on: Effective Direct Lambdas for AWS AppSync (Spoiler: they are really effective)

Collapse
conjohnerton profile image
John Connerton Author

Pros of VTL:

  • Useful utility methods.
  • More control with code execution before and after your Lambda is invoked.

Cons of VTL:

  • You have to learn a new language.
  • There is often boilerplate when you're simply forwarding data to the Lambda. (This is probably the best use-case for Direct Lambda, in my opinion)

More on that:
VTL has a lot of nice utilities built by AppSync. With it, you can do fine tuned time-stamping, string manipulation, batching, and other useful stuff like that. With the mapping templates, you also have the benefit of having full control over pre-invoke and post-response code execution. You have full control over the entire 'life-cycle' of the resolver.

With Direct Lambda, you have the option to relinquish a bit of that control and handle only the invoked Lambda. You can't do anything fancy before and after the Lambda, but you still have all the data that was originally available in the request mapping template, the Context object. If you can do it in VTL, you can do it in your Lambda. It's more about where the code is executed with this option.

About the performance, AppSync's resolver mapping template reference for Lambda touches on that briefly at the end of the page.

In some scenarios applications might experience less overhead and latency...

I take that as 'there is no VTL to execute, so there is no need to translate the data, and it is just passed through to the Lambda'. I believe that it can improve performance. By how much and in what cases? I'm not sure right now but that'd be a good experiment to run!