AWS AppSync uses GraphQL to create flexible API to secure access and manipulate data.
AWS AppSync stays in between client app instance and AWS web services, so let's AWS web service AWS DynamoDB, AWS Aurora, AWS Elasticsearch like so are connected using AppSync.
Here is the official diagram of how AppSync works. On the left side of the diagram there are client applications and on right there are AWS web service and in middle of both AWS AppSync is there which acts like Facilitator.
Benefits of using AWS AppSync
- Fast setup
- Real-time subscription and offline access
- Secure access
In order to make our instance secure we can add authentication using AWS Cognito . let's see how we can set AppSync for our client instance
- AWS account
- GraphQL basic understanding
let's jump into little bit of getting started with AWS AppSync here.
This is how the main AWS AppSync looks like. you can find it by searching for AWS AppSync in AWS console.
This is the basic default schema that is created by AWS AppSync. In the left there are 7 options available. let's understand important options
- Schema: For changing schema
- Data Sources: List of AWS DynamoDB tables that are created on creating resource
- Functions: For embedding AWS Lambda functions
- Queries: For accessing GraphQL queries that are created by AWS AppSync according to schema
- Settings: In this section there are API details, authentication mode, logging option etc
After updating schema click on > Save Schema > Create Resource. While creating resource you will be asked for two option Define new type and Use existing type select Use existing type this will show list of GraphQL type that were added in schema. The create resource screen will have list of pre-built GraphQL query, mutation, subscription and other method for selected schema type. On clicking Create button AWS AppSync will build AWS DynamoDB table.
Also you can test you GraphQL api from Queries section.
Above GraphQL api are not secure as authentication is not added. you can add authentication from Settings section and choose any of the given option
To use AWS Cognito user pool we must have to create pool. if you don't know how to create user pool refer below documentation
After setting up cognito user in Settings section when to go Queries Section you will see authorization provider as Amazon Cognito Pool which means that now all GraphQL endpoints are secured.
So, this is the most basic flow to get started with AWS AppSync. To use AWS AppSync offline you can use AWS Amplify which have some more concepts and different setup.
To learn more about AppSync security, please check our documentation. To get started with building applications and APIs with Amplify, refer to the Amplify Framework documentation. It provides a CLI, libraries and the GraphQL Transform that you can use to get started with developing critical security functionality in your application.