AWS AppSync
AWS AppSync Developer Guide

(Optional) Provision from Schema

AWS AppSync can automatically provision Amazon DynamoDB tables from a schema definition, create data sources, and connect the resolvers on your behalf. This can be useful if you want to let AWS AppSync define the appropriate table layout and indexing strategy based on your schema definition and data access patterns.


These instructions start with the schema outlined in Designing Your Schema, as shown next:

schema { query:Query mutation: Mutation } type Query { allTodo: [Todo] } type Mutation { addTodo(id: ID!, name: String, description: String, priority: Int, status: TodoStatus): Todo } type Todo { id: ID! name: String description: String priority: Int status: TodoStatus } enum TodoStatus { done pending }

From the AWS AppSync console, navigate to the Schema page, enter the preceding schema into the editor, and choose Save.

Provision from Schema

After you save a schema, a Create resources button appears in the upper right of the page. Click this to go to the Create resources page. You can select any user-defined GraphQL types from the screen, and your Todo type should be available. Select this type and you'll see a form you can use to configure the table details. You can change your DynamoDB primary or sort keys here, as well as add additional indexes. At the bottom of the page is a corresponding section for the GraphQL queries and mutations that are then available to you, based on different key selections. AWS AppSync will provision DynamoDB tables that best match your data access pattern for efficient use of your database throughput. An index selection is also available. You can use it for different query options, which set up a DynamoDB Local Secondary Index or Global Secondary Indexes, as appropriate.

For the preceding example schema, you can simply have id selected as the primary key and press the Create button. After a moment, your DynamoDB tables are created, data sources are created, and resolvers are connected. You can run mutations and queries as described in the Using Your API section. Note that there will be a GraphQL input type for the arguments of the created schema. For example if you provision from schema with a GraphQL type Books {...} then there might be an input type like so:

input CreateBooksInput { ISBN: String! Author: String Title: String Price: String }

To use this in a GraphQL query or mutation you would do the following:

mutation add { createBooks(input:{ ISBN:2349238 Author:"Nadia Bailey" Title:"Running in the park" Price:"10" }){ ISBN Author } }