Serverless AppSync Realtime Chat
- Node.js 8
npm install -g @aws-amplify/cli
- Serverless Framework
npm install -g serverless
- AWS credentials setup
- Fast option: credentials have Administrator access (not recommended).
- Slower option: add the following permissions to your account:
- CloudFormation - Read/Write (custom policy)
- AppSync - Administrator
- Cognito - Power User
- Clone repo
- Install backend dependencies
npm install # or yarn
- Deploy serverless stack
This command will create DynamoDB table with messages, Cognito User and Identity Pool and AppSync project.
After completing, this will create
stack.json file inside
front/src/ directory which will be later used for frontend part.
- Go to frontend part and install dependencies
cd front && yarn
- Now we need to generate API client for the frontend basing on GraphQL schema from AppSync service. First, we need to initialize Amplify in frontend directory.
- And then associate to our AppSync API.
amplify add codegen --apiId <API_ID_HERE>
You can retrieve API_ID from https://console.aws.amazon.com/appsync/home?region=us-east-1.
This should create following files inside your
front ├── .amplifyrc ├── .graphqlconfig.yml ├── src ├── API.ts └── graphql ├── mutations.js ├── queries.js ├── schema.json └── subscriptions.js
Now you can start your project by running
npm run frontif you are currently in root directory.
Head to http://localhost:3000, create your account, confirm, login and chat!