June 7th 2020
While using any services from AWS you can do it via their API,Console or CLI tool like amplify, amplify was designed specifically to work with AWS and to make it easier for developers to deploy applications on the cloud just by running some commands, In this blog i will be showing you how can you create an Appsync API with Amplify, It will have auto generated resolvers for all the queries,mutation and DynamoDB as the database.Yes you read that right everything will be created for you by AWS using cloudformation which acts as template for all the services that you will be needing. So before we get started i encourage you to install Amplify CLI on your computer and configure it with your Credentials. Let’s get started now.
Create a folder in your preferred directory and run the following command
This will initialize the folder as an amplify project and in the left hand side you can see all the boilerplate code already created for you.Configure all the setting according to your need or keep it as default.
Run the following command to add API to your amplify project.
Configure this using the following settings or modify if you wish.
amplify add api
In the above image you can see that for the question Do you have an annotated GraphQL schema, you can select yes if you have your schema in place.
Right now for this demo i am selecting No because then AWS will help me make a schema from scratch.
Now your GraphQL schema has been generated for your ToDo app you can see it in your folder structure.
Once you are satisfied with the schema that has been created you can run amplify push to publish all the changes to the cloud.
Now run the following command:
Now grab a cup of coffee and wait because it is going to take some time for your database,API and resolvers to be created.
Next choose if you want the resolvers to be created (Resolvers are used to tell the API how and where to fetch the data from)
This is not technically a step, here i will be discussing the folder structure and where you will find everything:
1. Resolvers for Query and mutation:
2. Query,mutation that will be sent from client side to the API:
Now you are all set to do query in your appsync console:
So as you saw an API was created in just few steps, AWS Amplify CLI makes it easier to develop your backend. Not only API but you can even add authentication and much more to your API using simple commands provided by Amplify CLI.