Bobcares

Configure an AWS AppSync to handle nested JSON data in DynamoDB

by | Feb 1, 2022

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:

Configure an AWS AppSync to handle nested JSON data in DynamoDB
  • 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

  1. First, we will open the AWS DynamoDB console and select Create table.
  2. Next, we have to enter a descriptive name in the Table name field and a field name in the Primary key field.
  3. Then we will click Create.
  4. After that, we have to select the Items tab and choose Create item.
  5. Next, we have to select Text from the upper left dropdown list in the Create item box.
  6. 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

  1. First, we have to open the AWS AppSync console and select Create API.

  2. Then, we will head to the Getting Started page and choose Build from scratch under Customize your API or import from Amazon DynamoDB.
  3. After that, we will choose Start. and enter a name for the API in the API name field.
  4. Next, we will click Create.
  5. Then, we have to choose Data Sources in the left navigation pan and select Create data source.
  6. 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
  7. Finally, we have to select Create.

How to configure the nested JSON schema in the AppSync API

  1. First, we have to select Schema from the left navigation pane of the AWS APPSync console.
  2. 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

  1. 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.
  2. Then, we will head to getItems(…): allData under Resolver and select Attach.
  3. 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.
  4. After that, we will select Save Resolvers.

How to create a new test query

  1. Here, we will select Queries from the left navigation pane in the AWS AppSync console.
  2. 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
        }
      }
  3. 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.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.