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.

已提問 5 年前檢視次數 415 次
7 個答案
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.

已回答 5 年前
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.

已回答 5 年前
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
已回答 5 年前
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
已回答 5 年前
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
已回答 5 年前
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

已回答 5 年前
0

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

Kiwiana
已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南