Configure an AWS AppSync to handle nested JSON data in DynamoDB with a little help from the experts at BObcares.
At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.
Let’s take a look at how our Support Team is ready to help customers configure an AWS AppSync to handle nested JSON data in DynamoDB.
How to configure an AWS AppSync to handle nested JSON data in DynamoDB
If you are looking for a way to configure an AWS AppSync schema to retrieve a response from an Amazon DynamoDB table with nested JSON data you are in the right place. Our Support Engineers have come up with a way to fix this issue. It involves the following steps:
- Adding a nested JSON data item to the DynamoDB table
- Creating an AppSync API & attach the data source
- Configuring the nested JSON schema in the AppSync API
- Attaching a resolver to the getItems query
- Creating a new test query
How to Add a nested JSON data item to the DynamoDB table
- First, we will open the AWS DynamoDB console and select Create table.
- Next, we have to enter a descriptive name in the Table name field and a field name in the Primary key field.
- Then we will click Create.
- After that, we have to select the Items tab and choose Create item.
- Next, we have to select Text from the upper left dropdown list in the Create item box.
- Finally, we will copy and paste the following in the text item and select Save.
{ "id": "123", "product": { "model": { "property": { "battery": "li-ion", "device": "iOT-Device", "pressure": "1012", "up_time": "02:12:34" } } }, "status": "In-Stock" }
How to create an AppSync API and attach the data source
- First, we have to open the AWS AppSync console and select Create API.
- Then, we will head to the Getting Started page and choose Build from scratch under Customize your API or import from Amazon DynamoDB.
- After that, we will choose Start. and enter a name for the API in the API name field.
- Next, we will click Create.
- Then, we have to choose Data Sources in the left navigation pan and select Create data source.
- After that, we will navigate to Create new Data Source on the New Data Source page and enter the following information:
- Data source name: Enter a descriptive name
- Data source type: Select Amazon DynamoDB table
- Region: Select the region containing the DynamoDB table
- Table name: Select the table created recently
- Finally, we have to select Create.
How to configure the nested JSON schema in the AppSync API
- First, we have to select Schema from the left navigation pane of the AWS APPSync console.
- Then, copy and paste the following into the text box and select Save Schema:
type Query { getItems(id: String!): allData } type allData { id: String! product: toModel status: String } type items { battery: String device: String pressure: String up_time: String } schema { query: Query } type toModel { model: toProperties } type toProperties { property: items }
How to attach a resolver to the getItems query
- First, we will open the AWS AppSync console and navigate to Schema > Resolvers >Query. Alternatively, we can also enter Query in the Filter types field.
- Then, we will head to getItems(…): allData under Resolver and select Attach.
- Next, we have to select the Data source name on the Create new Resolver page and select the name of the DynamoDB table we created earlier.
- After that, we will select Save Resolvers.
How to create a new test query
- Here, we will select Queries from the left navigation pane in the AWS AppSync console.
- Then we will head to the Queries page of the API in the Query editor and copy and paste the following query:
query getItem { getItems(id:"123") { id product{ model{ property{ pressure device battery up_time } } } status } }
- Next, we have to select the play icon. Alternatively, we can also press Ctrl/Cmd+Enter in order to run the test query.
[Looking for a solution to another query? We are just a click away.]
Conclusion
In essence, our skilled Support Engineers at Bobcares demonstrated how to configure an AWS AppSync to handle nested JSON data in DynamoDB.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments