You are viewing the preview version of this book
Click here for the full version.

Example application

Code example

Implementation here.

In this chapter we'll build a social network from scratch. It will be simple, but we'll touch a lot of aspects of making apps on top of AppSync.

The app will allow users to publish posts on their timeline and see their friends' posts as well as to write comments. Also, it will update the feed in real-time for new posts and comments.

Logging in, the app shows the current user's feed and the friends list:

The user's feed with the posts and friends lists

Commenting is possible for every post:

The comment form and the comments for a post

To implement this app, we'll:

  • Design a GraphQL schema
  • Implement authentication using a Cognito User Pool
  • Store data in DynamoDB
  • Implement resolvers for fields
  • Push real-time updates via Subscriptions
  • Add access control

The example repo uses Terraform for IaC, so you can easily deploy the project to your account and experiment with the code. Just don't forget to destroy it when you are done.

Don't forget to clean up the example code

If you deploy the example project in your account, don't forget to run terraform destroy to clean it up when you are finished.

While the API itself does not cost much when idle, there is a data generator Lambda function that is constantly running and calling the API. Over time, it can accumulate costs.