Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkHow to fast-track your GraphQL API creation
This hands-on guide will hold your hands through each step as you let AWS create a GraphQL API for you using a DynamoDB table.
If you already have a DynamoDB table you want to use, skip ahead to the next section. If not, then go ahead and create a table of magical kittens:
- Go to Services > DynamoDB
- Click Create table.
- For Table name, enter: Magical-Kittens-Table
- For Primary key, enter: kitten_id
- Click Create.
- Then Create item.
- For Item {1} kitten-id, enter: brit-shorthair1
- Click on the + and Append a Number: { age : 0.5}
- Append a String: { personality : fierce }
- Append a Boolean: { magical: true } and click Save.
Voila! You now have a table. Let’s make that API now:
- Go to Services > AWS AppSync.
- Click Create API.
- Select Import DynamoDB table and Start.
- Choose the Magical-Kittens-Table or another table from the dropdown and Import.
- Keep all the defaults and Create … and Create again.
And you’re done! AWS AppSync just created a GraphQL API for you. Let’s play with it:
- Change the "kitten_id" in the QUERY VARIABLES section at the bottom from "Hello, world!" to something more sensible, like "siberian1".
- Click the Play button and select the ‘create’ mutation from the dropdown. Congrats, your API just wrote a Siberian kitten to DynamoDB! 🦁
- You can verify the existence of the Siberian by clicking the Play button again and selecting the ‘list’ query from the dropdown. All your kittens show up on the right!
4. Click on Schema in the left-hand menu and you’ll see just how much work AWS AppSync did for you. Looks like it wrote 99 lines of code.
5. Click on the Export schema dropdown and select schema.graphql and Save it. You can now put it in version control.
6. Click on Data Sources on the sidebar. That’s where your DynamoDB table is referenced. 👀
This was just a quick introduction to the fun and wonders of AWS AppSync. For a more in-depth overview of the service, my Serverless Guru colleague Luke Vandekieft has made a detailed video: