AWS Appsync multiple dynamodb requesst in one dynamodb resolver - amazon-web-services

I would like to know if it is possible to have multiple dynamodb request using only one dynamo resolver in AppSync?
Or the only/best way to have more complicated processing is to use a lambda function ?

Practically, no. You even cannot query on multiple indices in a single resource definition for an query, indeed.
However, if you are to use that structure for joining multiple DynamoDB tables, you can attach resolvers not to the query entry; but to the field you want to relate on other fields.
I had an issue like relating users to another table for containing the posts and I've passed it by attaching a resolver aiming the Posts field of the User type.
This issue refers to a similar problem and is quite helpful for that kind of cases: https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/17
If it is not the case of yours, you can elaborate the question. I may look like guessing your purpose for relating tables, all in all.

Have you looked at batch resolvers with AWS AppSync?https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html
This will allow you to write to one or more tables in a single request, and also allow you to do multiple write/read/delete operations in a single request.

You can do it with pipeline resolvers
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-pipeline-resolvers.html

Related

Single table db architecture with AWS Amplify

By default AWS Amplify transformers creating tables per each graphql type.
But according DynamoDB documentation it's best practice to
Keep tables few as possible
Keep often queried together entries within a same table
I have an impression Amplify way of doing things stays in contradiction with the statement above.
I am new to both NoSQL and Amplify
Can someone suggest ways to address those issues?
I think we're in a bit of a transition or gray area here. I'm very new to Amplify and have been investigating moving to a single-table design as there are sources (below) that indicate that it's always be there but you'd have to write everything in VTL templates. But in 2020 they released direct lambda resolver support: https://youtu.be/EOQqi6Yun7g?t=960 (clip)
However, it seems like you lose access to the #auth directive (and probably others because you're no longer going to use #model) along with a lot of the nice out-of-the-box functionality that's available with Amplify's multi-table approach.
At this point, being that I'm developing a new app, I'm going to stick with the default multi-table design to hasten the process of getting the app functional.
Trying to implement the single-table design seems to go against what the Amplify team recommends and requires more manual work. You'd have to manually create custom lambda functions (AppSync) and code queries to DynamoDb for each data access element and manage authorization through some other means which I'm not aware of at this time. Maybe someone can chime in here...
Single table vs multi table info
Using Amplify with single table:
https://youtu.be/EOQqi6Yun7g
Single vs Multi Clip:
https://youtu.be/1WF_wped808?t=1251 (clip)
https://www.alexdebrie.com/posts/dynamodb-single-table/ (towards bottom)
https://youtu.be/EOQqi6Yun7g?t=1288 (clip)
Example single table design by Alex Debrie:
https://gist.github.com/dabit3/96dc51e688b18a7d40fc534331758c56
More Discussion:
https://stackoverflow.com/a/56438716/1956540
Basic Setup steps
I setup a single table by following the below instructions. Again, you don't use #models for this. Also, I think you have to include a type query {} in your schema for it to compile, but I could be wrong here.
So the basic steps are:
Create a single table (amplify add storage)
amplify push
Create your schema in the schema.graphql file.
Create supporting lambda function (amplify add function)
Note: if you look at the example here, I believe you can create an entry point to routes to all other methods: https://gist.github.com/dabit3/96dc51e688b18a7d40fc534331758c56#lambda
Add the DynamoDb query code in the function.
amplify push
Complete steps for Setting up a single Table:
https://catalog.us-east-1.prod.workshops.aws/workshops/53b10bf8-2271-4ab4-bfd2-39e878a90dc8/en-US/lab2/1-vtl (both "Connecting to an existing DynamoDB table" and "Direct Lambda Resolver" steps)
Not trying to be negative about Amplify, it is awesome, I love what they are doing with this product. I just think it's very new to everyone and I'm hoping this post is no longer valid next year and we continue to see great progress from the team.

Appsync query on relation child object

I am in the situation of mutation to create relations on AWS AppSync
I have events in one table, comments in another. In my graphql events type I have a field for list of comments with its own resolver
I would like to know how I can request only events that have comments, in the same way.
My situation makes I need also to filter which events I want to show so I can not start by getting list of distinct events in the comment table.
I would not like if it can be avoided to create a pipeline with specific resolver, to avoid code duplication.
Code can be retrieved to the linked stackoverflow question.
Thank you for help

How attach resolvers for each field in Appsync and query after

I need you help.
Currently I'm working with AppSync, and I know how to create resolvers, pipelines, etc. But I don't know how to use the fields resolvers. For example, I attach a resolver for each field of my type, because some fields have different sources, but if I want to query the "type", I need to create a new resolver for the query operation "getCustomer"? what is the correct way to use the field resolvers?
Please if possible an example of each resolve in VTL.
Thanks for your help.
Yes, you should create a resolver on the getCustomer query also.
This will be performed first and the results will be available in the context when resolving the field level resolvers.

AppSync Batch Update Item?

According to the documentation, it seems like AppSync doesn't support BatchUpdateItem (only supports BatchPutItem and BatchGetItem). I have a use case where I want to update a particular attribute of multiple items in a table. Is there an efficient way to do this in AppSync and DynamoDB? I cannot do a batchPutItem because I could be overwriting the item with expired attributes (another client updated an attribute). So the only option is to do UpdateItem one item at a time. I am thinking of having a loop in my iOS app that calls UpdateItem n times. Does this mean that there would be n network rounds? I want to be efficient with my design. Is there anyway I can do all the updates in one network round trip? Thank you.
Is there anyway I can do all the updates in one network round trip?
I think you're on to a reasonable approach with this line of questioning.
You could try setting up a mutation to be handled by a Lambda function data source. Have the Lambda function do your looping and report back with any conflicts. That way you can do it all in one network call.
More about Lambda resolvers here: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html
To update items you can call BatchPutItem with given ids. It will be overwritten.

Can you create views in Amazon Athena?

Is it possible to create views in Amazon Athena?
Since an External table is essentially metadata for data stored in files on S3, there's no transformation involved. Therefore, you can't handle data inconsistencies. Quite often, this can result in tables being defined with lots of string fields.
Can you create a view over the top of the External table that can contain the transformation logic, allowing users to query a "cleansed" view of the data?
Looks like they have added this support now AWS Doc
While that is a nice feature that you are looking for,
AWS Athena does not support creating any view.
Reference Documentation of supported DDL's:
http://docs.aws.amazon.com/athena/latest/ug/language-reference.html
Hope it helps.