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.

gefragt vor 5 Jahren415 Aufrufe
7 Antworten
0

AppSync blocks access to all tools and macros by default and the $math tool is included. I will record a feature request to look into enabling a subset of the built in tools for use cases like this. In the meantime, I would suggest using a lambda resolver.

beantwortet vor 5 Jahren
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.

beantwortet vor 5 Jahren
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.

Kiwiana
beantwortet vor 5 Jahren
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
beantwortet vor 5 Jahren
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.

Kiwiana
beantwortet vor 5 Jahren
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

beantwortet vor 5 Jahren
0

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

Kiwiana
beantwortet vor 4 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen