AWS AppSync as a Gateway to Your Cloud Infrastructure

When you build modern cloud-based systems, you usually realize quickly that you need to manage the access to your deployed resources. This is especially true with serverless systems, where you often end up with dozens of resources, even for medium-sized architectures. 

AWS offers a few services you can use to set up a central entry point to your infrastructure. Elastic Load Balancer, API Gateway, and AWS AppSync. 

This article will discuss AppSync, AWS’s managed GraphQL service. Read on if you’re building a new backend or want to see if there is a more refined solution to the gateway problem than ELB and API Gateway.

What is AWS AppSync?

AppSync is a serverless GraphQL service. In simple terms, it’s just an API gateway based on the GraphQL specification you can pay on-demand.

GraphQL offers a friendly query language on top of HTTP, making it possible to fetch multiple different resources in one request, lowering network latency.

It’s higher level than Amazon API Gateway because it builds on HTTP and WebSockets but doesn’t expose these protocols directly to the user. Instead, it offers a data modeling language for queries, mutations, and subscriptions. This distinction makes it a good candidate for the Command Query Responsibility Segregation architectural pattern popularized by Domain-Driven Design. 

These characteristics allow you to build real-time and offline applications without thinking about the heavy lifting in the background.

AppSync works with AWS Amplify, a set of client libraries, and a command line interface. It has libraries for JavaScript (vanilla, React, Angular, React-Native, Ionic), iOS, Android, and Flutter.

How Does AWS AppSync Work?

AppSync allows you to define a GraphQL schema and link every type to a resolver. You can implement these resolvers in the Velocity Templating Language (VTL) or, when using AWS Lambda as a resolver, in a programming language of your choice. Keep in mind that Lambda resolvers incur extra costs.

VTL Resolvers

VTL is a rather templating language that maps one string to another. This way, you can transform the data coming from AppSync to fit an upstream service. While it takes a bit to get used to, VTL resolvers are much cheaper and have lower latency than Lambda resolvers. 

Depending on your skills, you might want to start with Lambda resolvers and change them to VTL resolvers when you notice cost or latency problems.

Lambda Resolvers

You have to pay for every invocation of a Lambda resolver but get much more flexibility from them. You can implement them in all languages Lambda supports, and since they’re just Lambda functions, you can do whatever you want. 

If you wish to link AppSync to a custom service or want to perform multiple tasks in one resolver, then VTL won’t cut it.

AWS Amplify CLI & Libraries

You would primarily use AppSync with the help of AWS Amplify, a set of libraries, and a command line interface. 

The Amplify CLI can generate CloudFormation templates and client code based on a GraphQL schema. This way, you can deploy an API and DynamoDB tables and get an extensive client library with just a few lines of code. If you change the schema, Amplify CLI can automatically update the rest of your stack.

The client libraries come with support for subscriptions and abstractions built on them. The DataStore, for example, uses AppSync to let you create offline-enabled apps that sync with the cloud in real-time. 

What are the Benefits of Using AWS AppSync?

AppSync allows you to build sophisticated apps without the need to set up or maintain your GraphQL server. You pay only for what you use, and AWS will keep the service up-to-date for you.

It comes with solutions for real-time and offline apps out-of-the-box. You can deliver these features to your users in a matter of hours instead of weeks.

Also, it gives you some exciting features like filtering subscription data in the backend to ensure your clients won’t get overwhelmed by real-time updates they don’t need.

And finally, when you use AppSync with Amplify, you can generate infrastructure templates and client libraries directly from your GraphQL schemas.

AWS AppSync vs. API Gateway

API Gateway is a more low-level service than AppSync. It exposes HTTP requests and WebSocket connections. 

Before AppSync was released, you had to build a GraphQL API with API Gateway and Lambda. A Lambda function had to use a GraphQL server library, like Apollo, to do all the work.

If you wanted to use GraphQL subscriptions, you had to set up an API Gateway WebSockets API and build that subscription feature all by yourself with a Lambda function.

In the end, you would have much more implementation and maintenance work and even pay for the API Gateway and the Lambda functions.

On the other hand, if you want to build a simple API that doesn’t need many features and is all about performance, a well-designed API Gateway endpoint could be a better solution for your workload.

What does AWS AppSync Cost You?

AppSync is a 100% serverless service; it doesn’t cost you a dime if nobody uses it. You even get 250,000 requests a month for free with a new AWS account in your first 12 months.

Had an idea that didn’t get any customers? No risk with serverless!

Otherwise, AppSync is a bit more costly than API Gateway. 

You pay $4 for 1 million queries and mutations and $2 for 1 million real-time updates via subscriptions. There is also a connection cost for the subscriptions: 1 million connection minutes cost $0.08.

Summary

AWS AppSync and AWS Amplify are good services to get your GraphQL API off the ground quickly with low maintenance costs in the future.

AppSync is more sophisticated than API Gateway but comes at a higher price. 

If you want GraphQL-powered, real-time, offline enabled applications with code generators for infrastructure and client libraries, AppSync and Amplify are the way to go.

PS! Dashbird is launching AppSync integration very soon. If you want to be one of the first to hear about it, sign up for our newsletter.

Read our blog

ANNOUNCEMENT: new pricing and the end of free tier

Today we are announcing a new, updated pricing model and the end of free tier for Dashbird.

4 Tips for AWS Lambda Performance Optimization

In this article, we’re covering 4 tips for AWS Lambda optimization for production. Covering error handling, memory provisioning, monitoring, performance, and more.

AWS Lambda Free Tier: Where Are The Limits?

In this article we’ll go through the ins and outs of AWS Lambda pricing model, how it works, what additional charges you might be looking at and what’s in the fine print.

More articles

Made by developers for developers

Dashbird was born out of our own need for an enhanced serverless debugging and monitoring tool, and we take pride in being developers.

What our customers say

Dashbird gives us a simple and easy to use tool to have peace of mind and know that all of our Serverless functions are running correctly. We are instantly aware now if there’s a problem. We love the fact that we have enough information in the Slack notification itself to take appropriate action immediately and know exactly where the issue occurred.

Thanks to Dashbird the time to discover the occurrence of an issue reduced from 2-4 hours to a matter of seconds or minutes. It also means that hundreds of dollars are saved every month.

Great onboarding: it takes just a couple of minutes to connect an AWS account to an organization in Dashbird. The UI is clean and gives a good overview of what is happening with the Lambdas and API Gateways in the account.

I mean, it is just extremely time-saving. It’s so efficient! I don’t think it’s an exaggeration or dramatic to say that Dashbird has been a lifesaver for us.

Dashbird provides an easier interface to monitor and debug problems with our Lambdas. Relevant logs are simple to find and view. Dashbird’s support has been good, and they take product suggestions with grace.

Great UI. Easy to navigate through CloudWatch logs. Simple setup.

Dashbird helped us refine the size of our Lambdas, resulting in significantly reduced costs. We have Dashbird alert us in seconds via email when any of our functions behaves abnormally. Their app immediately makes the cause and severity of errors obvious.