Simple app that broadcasts messages to multiple clients using Serverless GraphQL real-time subscriptions powered by AWS AppSync.
The API access is authenticated via API Key valid for 7 days. The demo takes advantage of GraphQL Subscriptions to send messages in real-time to different clients. Messages are saved to a DynamoDB data source.
- AWS Amplify CLI
(npm install -g @aws-amplify/cli)
- Create React App
(npm install -g create-react-app)
-
Clone the repository
-
Install the required modules:
npm install
-
Init the directory as an amplify Javascript project using the React framework:
amplify init
-
Add an AppSync GraphQL API with API Key for the API Authentication. Follow the default options. When prompted with "Do you have an annotated GraphQL schema?", select "NO" and copy/paste the schema from the file
schema.graphql
in this repo. It will use a GraphQL Transform directive @model to deploy and configure a DynamoDB table to store messages:amplify add api
-
Test locally with http://localhost:300 using multiple browsers
amplify serve
-
Execute
amplify add hosting
from the project's root folder and follow the prompts to create an S3 bucket (DEV) and/or a CloudFront distribution (PROD). If you are deploying a CloudFront distribution, be mindful it needs to be replicated across all points of presence globally and it might take up to 15 minutes to do so. More info on the Amplify CLI docs.
-
Build, deploy, upload and publish the application with a single command:
amplify publish
Access the app from multiple devices or send the S3/CloudFront/AmplifyApp.com link to friends to test Serverless GraphQL real-time subscriptions