Preparation

  1. Create a table in DynamoDB with the following command:
aws cloudformation create-stack \
    --stack-name AWSAppSyncTutorialForAmazonDynamoDB \
    --template-url https://s3.us-west-2.amazonaws.com/awsappsync/resources/dynamodb/AmazonDynamoDBCFTemplate.yaml \
    --capabilities CAPABILITY_NAMED_IAM

After running this command a AppSyncTutorial-Post table is created

  1. Create GraphQL API with AppSync console

CreateAPI

  • Click Create API

CreateAPI

  • Choose Create with wizard, then click Start

CreateAPI

  • Enter Model name - AWSAppSyncTutorial

  • Click Remove field to remove unnecessary fields

  • Click Create CreateAPI

  • Enter API name, such as AWSAppSyncTutorial

  • Click Create CreateAPI

  • Once created, select the Schema tab in the menu on the left

CreateAPI

  • Replace content with below code, then click Save Schema
schema {
    query: Query
    mutation: Mutation
}

type Query {
    getPost(id: ID): Post
}

type Mutation {
    addPost(
        id: ID!
        author: String!
        title: String!
        content: String!
        url: String!
    ): Post!
}

type Post {
    id: ID!
    author: String
    title: String
    content: String
    url: String
    ups: Int!
    downs: Int!
    version: Int!
}

CreateAPI

  • Next, to create source for API, choose Data Sources tab
  • Click Create data source

CreateAPI

  • Enter source name, such as: PostDynamoDBTable
  • Select DynamoDB table for data source type
  • Select the region that created DynamoDB table
  • Select AppSyncTutorial-Post table
  • Select New role and click Create

CreateAPI

  • Result after creation:

CreateAPI