AWS Java SDK - How to Connect a dynamodb through AppSync - amazon-dynamodb

We have a table in DynamoDB and we need to fetch data from the table using AppSync using AWS Java SDK.
AWSAppSync awsAppSyncClient;
public UserManagementAppSyncService(AWSCredentialsProvider credentialsProvider) {
this.awsAppSyncClient = AWSAppSyncClientBuilder.standard()
.withRegion("eu-central-1")
.withCredentials(credentialsProvider)
.build();
}
How to achieve this further? I cannot find further code to do this. Any leads?
The Resolvers were generated from a GraphQL schema using Schema first approach. It is a maven project AND the generated resolvers are in target folder.

You do not actually need to run your Java code to connect AppSync to DynamoDB.
Instead you attach resolvers to your schema and just configure your mappings using VTL language. You can find the documentation of what it can do here.
When you attach a resolver to a graphql field in the AppSync console you can select a sample template that fetches dynamo item by Id:
If you really have to run your own code with custom business logic you can make use of Lambda Resolvers or if you want to skip the mapping template work you can also use Direct Lambda Resolvers

Related

How Do I Change An Existing DynamoDB Table's Pricing Model in AWS Amplify?

Problem: AWS Amplify has built all my tables with the "On-Demand" pricing model.
How can I change "On-Demand" to provisioned and set the read and write capacity units?
Requirements:
Cannot lose data in the table
Has do be done following the infrastructure as code principals, where I run amplify push apiName to push the new changes
You cannot set the billing mode of your DynamoDB table directly using the Amplify CLI, however you can override the base functionality by extending the Amplify Cloudformation stack with the use of CDK (Cloud Development Kit).
With the Storage Module you can run amplify override storage to create an override.ts file to add custom CDK Typescript code to override the base functionality of your Storage resources created via the Amplify CLI.
This will append these changes to your existing Amplify Cloudformation stack and apply these changes when you run amplify push to provision your stack.
For your DynamoDB tables you can customize the following properties of the dynamoDBTable and override the changes of the attributes you need. For example to update the read and write capacity you would override the ProvisionedThrought property and update the Read and write capacity units value to your desired amount. Below is an example of TypeScript code which shows this.
import { AmplifyDDBResourceTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyDDBResourceTemplate) {
resources.dynamoDBTable.billingMode = 'PROVISIONED'
}
https://docs.amplify.aws/cli/storage/override/#customize-amplify-generated-s3-resources

How to set up a database on startup in AWS amplify?

I have an amplify and I get how to add an api function, use a lambda layer etc. What I don't see is how to create the database on startup -- it appears from the documentation that this is done from a CloudFormation stack, but I still can't see how to ensure that the database is set up on startup of the app (or build the tables if not) using something like SQLAlchemy.
What's the intended flow here?

Does aws appsync have scan operations to scan dynamoDB

I am building a serveless web app with aws amplify - graphql - dynamodb. I want to know what exactly a scan operation is in this context. For example, I have an User table and queries listUsers and getUser were generated from amplify schema. Are they scan operations or queries?
Thank you for your answers in advance as I could only find the definition of a scan operation but there aren't example for me to identify one when it comes to graphql.
Amplify uses Filter Expressions which are a type of Query.
You can see this yourself by looking at the .vtl files that amplify generates and uploads to appsync.
They are located here: amplify/#current-cloud-backend/api/[API NAME]/build/resolvers
In that folder you can open up one of the Query.list[Model].req.vtl. Even if you are not familiar with Velocity Template Language you can still get the idea. You can see that it uses the expression $util.transform.toDynamoDBFilterExpression.
More info about that util and then looking at the docs for toDynamoDBFilterExpression.

Using java to stream index into elastic-search from dynamodb using trigger

I am a novice on dynamodb and elasticsearch.
Need to stream indexes into elastic search from dynamodb table by trigger using Java i.e. whenever a new record is inserted in dynamodb table the same has to updated in the elastic-search.
Most of the examples available in web are either incomplete or implemented in python/nodejs. If there can be any explanation on how to achieve this in Java or any links/reference articles are also welcome.

How to programmatically create a database in ADX using Java

I am using REST API (https://learn.microsoft.com/en-us/azure/kusto/api/rest/request) to interact with the database in ADX.
I want to create more databases in the same cluster. How should I do it using Java?
I am not using the Java SDK. I have relied on the REST APIs so far.
I think I cannot create a new database using the REST API, so looking for alternative.
It would have been really helpful if there was a command like ".create table tablename" just for the database.
Clusters and databases can be managed using the "Control Plane", aka ARM APIs. These APIs have libraries in different languanges (as well as REST).
For instance, for the java library use this link, for C# use this link
Example for how to create a database in C# library (Java should be very similar):
var database = managementClient.Databases.CreateOrUpdate(resourceGroup, clusterName, databaseName, new Database(location, softDeletePeriod: softDeletePeriod, hotCachePeriod: hotCachePeriod));
Read more here
I think you'll need to use the Azure ARM REST API since the database is treated as a resource. From that point you can interact with it through the ADX APIs.

Resources