Skip to content

How do we use build-in velocity tools inside resolvers?

0

I've got a resolver that I want to generate a random number and persist it to dynamoDB. I want to be able to use the MathTool (https://velocity.apache.org/tools/2.0/apidocs/org/apache/velocity/tools/generic/MathTool.html) to generate the pseudo random number. What is the method for loading and using the velocity tools? I've tried to access the built-in tools by reference (https://velocity.apache.org/tools/devel/tools-summary.html), but none of them seem to be loaded and the calls silently fail. Here's what I would like to accomplish:

#set($token = $math.random(100000, 999999))
$util.qr($context.args.input.put("token", $token))

I don't get any compilation errors, but it seems that the value of "$token" is always "true" and not the value of the generated number. Perhaps I am just not using it correctly, but the tools do not show up in autocomplete inside the resolver editor, so I want to make sure this type of behavior is even available.

6 Answers
0

Thanks for the info! We're using the Amplify framework which generates VTL templates by default which is why I went down this path, but I'll take a look at a lambda resolver.

answered 7 years ago
0

Hi @MichaelParis,

I have the same issue, trying to write processing logic in VTL which requires MathTool and SortTool and those are not supported at the moment.

By the way would you be able to comment on performance of native AppSync resolvers with Get/Put/Scan/Query Dynamo DB logic chained as a pipeline resolver functions versus the same logic but implemented using Lambda resolvers?

I'm interested in how AppSync handles the requests in those two different scenarios under the hood, especially will the latency and response time be comparable for both, or using native AppSync resolvers is more beneficial and recommended?

Thanks.

answered 7 years ago
0

A pipeline resolver is essentially a set of function resolvers executed sequentially. So let's say the DynamoDB Put resolver takes "x" ms, and Scan resolver takes "y" ms, if you add these to the pipeline, it would essentially take "x+y" ms to resolve the field.

If you use a Lambda resolver, there is an additional hop in the flow of your request, so it could have additional latencies involved, since your request would be sent to the Lambda function, which in turn hits the DynamoDB tables.

AppSync <=> DynamoDB (DynamoDB resolver)
AppSync <=> Lambda <=> DynamoDB (Lambda resolver)

AWS AppSync does not recommend one over the other, it really depends on the use case and you should choose a strategy that works best for you.

AWS
answered 7 years ago
0

Hi @Shankar-AWS and thanks for the comment,

I’m wondering if you’d be able to comment on this thread https://news.ycombinator.com/item?id=17551502

From what it looks like appwiz recommends VTL over Lambda wherever it’s possible, and also not clear if VTL are still a subject to cold starts.

Thanks.

answered 7 years ago
0

Is there a space we can track this?

Thought I would sign up to show my interest in this being added.

To maintain a evenly spaced DynamoDB key spacing I using sharding, with the scatter and gather idea.

Having to use a lambda to generate a random number between a range would be an extra cost etc. for something that could be done in the request resolver.

I feel like this is quite an important addition to encourage and implement good noSQL design with ease.

It's a +1 from me :)

Thanks

answered 7 years ago
0

There is a feature request for that: https://github.com/aws/aws-appsync-community/issues/40

answered 6 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.