DEV Community

Sebastian Korfmann
Sebastian Korfmann

Posted on

AWS AppSync Direct Lambda vs DynamoDB Resolver

I've been experimenting with AWS AppSync and I'm intrigued by the idea of ditching VTL entirely in favour of Direct Lambda Resolvers. Ignoring the monetary cost aspect which Lambda adds, my biggest question was the performance impact this might have. So, I ended up doing some basic real world tests.

Setup

A direct lambda resolver for the field Query.getNote and a VTL DynamoDB resolver for Query.ddbGetNote. Both versions are performing a GetItem operation on the same DynamoDB table.

1st Attempt

The first try with a Lambda function mostly in AWS CDK default configuration (i.e. 128 MB Ram) was quite disappointing.

Alt Text

The (warm) Lambda resolver took ~ 200 ms compared to 14 ms of the VTL DynamoDB call. Interestingly enough, most time consuming in the Lambda function appears to be the DynamoDB call. This seems odd.

Back to the drawing board?

A bit of research suggested, that this is an issue for underpowered Lambda functions. I've found this slide deck with a nice chart for balancing performance / costs for DynamoDB calls in Lambda functions.

Alt Text

The sweet spot seems to be around 512 MB memory for a Lambda function.

2nd Attempt

I changed the Lambda function to 512 MB and left everything else as it was. And surprise, surprise - This looks way better now.

Alt Text

Now the (warm) Lambda resolver takes ~ 30 ms compared to still 14 ms of the VTL DynamoDB call.

Conclusion

Skipping VTL in favour of direct Lambda resolvers seems to be reasonable for the gained flexibility, even though there are a few drawbacks. There's a bit of an overhead to call the Lambda function, which gets drastically worse on cold starts (+ ~ 600 ms).

In terms of costs, 1 million invocations at 100 ms with 512 MB would clock in at roughly 1 USD. That's on top of the 4 USD per million operations in AppSync. All in all, not exactly cheap in scale but nothing I'd be concerned about for now. That's something to optimize when costs would become an issue.

I'll continue to explore Direct Lambda Resolvers for all cases and report how it goes :)

Top comments (2)

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

lambda cold starts are shockingly bad. Also the lambda runtime seems unable to work multiple request / responses at a given time, so your whole 128-512MB is taken up per-request.

1000 concurrent requests = 1000 lambdas * RAM
512 GB RAM to serve 1000 requests...

Collapse
 
javiasilis profile image
Jose

Sebastian, thank you so much for this article. As I am requiring custom business logic, I am using most of my AppSync code through VTL + Lambda (Before the existence of Direct Resolvers).

I didn't know Direct Resolvers were introduced last year until fairly recently (Think it was back in May), and I wanted to see if the Lambda overhead was reduced. I think it still hasn't.

Anyways, it's a great thing that AWS has allowed us to do that, other possibilities that we have is to circumvent the 25 item limit from DynamoDB that is present in VTL templates.