Running Serverless Realtime GraphQL Applications With AppSync

Running Serverless Realtime GraphQL Applications With AppSync

About the Book

This is a book for developers, architects and technology leaders who want to learn about the latest generation of cloud technologies and how to build highly scalable, responsive web sites and APIs.

  • Share this book

  • Categories

    • Amazon Web Services
    • TypeScript
    • Infrastructure as Code
    • Software Architecture
  • Feedback

    Email the Author(s)

About the Authors

Gojko Adzic
Gojko Adzic

Gojko Adzic is a partner at Neuri Consulting LLP. He He one of the 2019 AWS Serverless Heroes, the winner of the 2016 European Software Testing Outstanding Achievement Award, and the 2011 Agile Testing Days Most Influential Professional award. Gojko's book Specification by Example won the Jolt Award for the best book of 2012, and his blog won the UK Agile Award for the best online publication in 2010.

Gojko is a frequent keynote speaker at leading software development conferences, and one of the authors of Narakeet and MindMup. As a consultant, Gojko helped companies around the world improve software delivery, from some of the largest financial institutions to small innovative startups.

To get in touch, write to or visit

Slobodan Stojanović
Slobodan Stojanović

Slobodan Stojanović is CTO of Cloud Horizon, a software development studio based in Montreal Canada, and CTO of Vacation Tracker, a simple Slack-based leave management system for teams. He is based in Belgrade and is the JS Belgrade meetup co-organizer.

Slobodan is the AWS Serverless HeroClaudia.js core team member, and co-author of the “Serverless Applications with Node.js” book, published by Manning Publications.

Table of Contents

  • Introduction

  • Here is what we’re going to build

    • Quick domain intro
    • Upollo architecture:
  • Appsync in five minutes

    • What is AppSync?
    • When to use AppSync?
    • When not to use AppSync?
    • Why GraphQL?
    • How AppSync works with other AWS services?
  • CDK in five minutes

    • Infrastructure as code – literally
    • Why CDK?
    • CDK constructs
    • How CDK compares to other deployment tools
    • Setting up CDK for local development
    • Setting up your AWS account
    • Testing the configuration
  • Part 1: Basic Development tasks

    • Your first AppSync app

      • Hello World from CDK and AppSync
      • Deploying an AppSync App
      • AppSync application structure
      • Generating API Keys
      • Retrieving CloudFormation outputs with CDK
      • Trying it out from the AWS console
      • Trying it out from the command line
      • Troubleshooting Appsync
      • Accessing Data Sources from AppSync
      • What are AppSync Resolvers?
      • Troubleshooting deployments
      • How to remove deployed applications
      • Other Authentication options
      • Where to find more information?
    • Building a simple GraphQL Schema

      • Modelling GraphQl Types
      • Modelling GraphqQL operations
      • Verifying your schema
      • VTL template basics
      • Passing arguments using AppSync VTL context
      • Formatting results using AppSync VTL utility functions
    • Testing AppSync applications

      • Simulating AppSync for local tests
      • Automated integration-testing with AppSync
      • Securing access using IAM
      • Testing API access
      • Unit testing VTL templates
  • Part 2: Working with persistent data

    • Connecting AppSync to DynamoDB

      • Why DynamoDB?
      • Adding a database using CDK
      • Accessing DynamoDB items using the web console
      • Accessing DynamoDB records from the command line
      • Reading from DynamoDB via AppSync: getSurveyById
      • VTL templates for DynamoDB
      • Integration testing AppSync with DynamoDb
    • Working with Mutations

      • Scope for this chapter
      • Saving to DynamoDB using AppSync: createSurvey
      • Creating unique IDs in resolvers using util.autoId
      • Updating existing Dynamo records
      • Using update conditionals to preventing accidental object creation
    • Single-table dynamo design

      • How Dynamo tables compare to SQL tables
      • Why single tables?
      • Modelling relations with single-table design
      • Example Upollo records
      • Migrating resolvers to single-table design: saving answers with createSurvey
      • Using Dynamo batch writes for performance
    • Accessing object graphs with GraphQL

      • Using DynamoDB queries to list collections by prefix
      • Accessing object graphs using GraphQl subitem queries
      • Adding answers to getSurveyById
      • Queries for lists: getAnswersBySurveyId
      • Using pipeline resolvers to customise output
      • Sharing VTL templates between resolvers: how to read ID from stash or args with util.defaultIfNull
      • Testing hierarchical resolvers
    • Performing complex updates

      • Atomically updating Dynamo item fields
      • Using DynamoDB transaction writes for consistency
      • Processing votes: addVote
      • Capturing timestamps using $util.time.nowISO8601
  • Part 3: Working with web clients

    • Introduction to AWS Amplify

      • Using the aws-amplify React Client
      • Creating and deploying an Amplify App that connects to AppSync
      • Running graphQL queries
      • Executing GraphQl mutations
    • Authenticating users with AWS Cognito

      • What is Cognito?
      • User pools
      • Hosted UI
      • Allowing Cognito access in GraphQL
      • Testing Cognito access from the AWS Web console
      • Integrating Cognito with Amplify Apps
      • Modelling data security using GraphQl
      • Restricting data reads using AppSync
      • Dealing with unauthorised access on the front end
    • Realtime updates with GraphQl subscriptions

      • How GraphQl subscriptions work?
      • Declaring Subscriptions in the schema
      • Triggering subscriptions with mutations
      • Subscribing to updates using Amplify SDK
  • Part 4: Connecting to other services using AppSync Resolvers

    • Using AWS Lambda for custom processing

      • Converting data using Lambda
      • Connecting to other AWS Services (S3)
      • Using Lambda logs for CloudWatch metrics
    • Searching using ElasticSearch/OpenSearch

      • Updating ElasticSearch documents using DynamoDB streams
    • Connecting to external APIs using HTTP resolvers
    • Processing transient data with local resolvers
      • Triggering custom notifications
  • Part 5: Operating AppSync applications

    • Working with deployment pipelines

      • Setting up for teamwork
      • Deploying CDK apps using AWS CodePipeline
      • Deploying AWS Amplify Apps
      • Managing dev, test, staging and production stacks
      • Configuring using SSM
    • Monitoring AppSync applications

      • ClodudWatch logs
      • CloudWatch insights
      • Adding custom metrics
      • XRay
    • Setting up a custom domain

      • Integrating AppSync APIs with CloudFront distributions
      • Deploying to multiple regions
  • Part 6: Quick reference guide

    • GraphQL reference

      • Types
      • Mutations
      • Queries
      • Subscriptions
      • AppSync extensions
    • VTL reference

      • What is VTL?
      • Conditions
      • Loops
      • AppSync context
      • AppSync Utility functions

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub