๐Ÿ”“ Unlock the Power of GraphQL with AppSync โ€“ Discover How!


๐Ÿ‘€ This is not properly displayed? Read all of our issues online! ๐Ÿ’ก

Hi Reader ๐Ÿ‘‹๐Ÿฝ

we now finished all service introductions which we also showed you in the AWS Fundamentals Book ๐ŸŽ‰.

That doesn't mean we run out of content! There are still many services we want to give you introductions and 1x1 to. Once we finish this, we will grow together with you and do more deep dives into use cases, configurations, and all you can do with AWS.

Today's newsletter is about another API service: AppSync. AppSync is a managed GraphQL API.

For this newsletter, we also have something special. We've invited the AppSync Pro, Benoรฎt Bourรฉ. Ben is a consultant at Serverless Guru, builds a SaaS for a better AppSync Developer Experience, and creates a lot of content around AppSync. He shows us what AppSync is and how to use it.

AppSync Infographic

The infographic shows you all the information about AppSync on one sheet. If you need a refresher after reading this issue, check it out.

That's it from us, let's hear it from Ben

Introduction

Hey AWS Fundamentals Community ๐Ÿ‘‹๐Ÿฝ

Iโ€™m Benoรฎt. Some of you might already know me from Twitter/X where I often share content about serverless. In this episode, I will introduce you to AWS AppSync.

AppSync is a fully managed and serverless service from AWS that allows developers to build GraphQL APIs at scale. It integrates with many other AWS services such as Amazon DynamoDB, AWS Lambda, Amazon EventBridge, Amazon Aurora, Amazon OpenSearch, and Amazon Cognito.

Introduction - GraphQL

GraphQL is an open-source data query and manipulation language for APIs and a query runtime engine. It was created by Facebook in 2012 before being made publicly available in 2015.

GraphQL supports three types of operations:

  • Queries: Used to read or fetch data from the data sources. Queries are analogous to HTTP GET requests in RESTful APIs.
  • Mutations: Used to write or update data. They are equivalent to PUT, POST and DELETE operations in REST.
  • Subscriptions: Used for real-time pub/sub communication with the backend.

GraphQL offers distinct advantages compared to REST, addressing and mitigating two common inconveniences:

  • Overfetching: This occurs when a client receives more data than it requires.
  • Underfetching: In REST, underfetching happens when a client needs additional data beyond what is provided in a particular endpoint response, requiring subsequent requests.

GraphQL allows clients to specify the exact data they need in a single request, avoiding unnecessary network latency and overhead.

Here is an example request:

Authentication and Authorization with AppSync

Authentication and authorization are important for every API. You don't want to expose each query and mutation to the public.

AWS AppSync offers 5 different ways to authorize users.

  • Amazon Cognito: Users can invoke the API using a Cognito JWT.
  • Api Key: It can be used for simple use cases such as โ€œanonymousโ€ requests.
  • OIDC: Allows you to integrate with any identity provider that supports this protocol. (e.g. Auth0, Okta, etc)
  • Lambda: Allows you to run custom business logic to determine if the user should be authorized or not.
  • IAM: Requires clients to pass an IAM signature. The role and policies associated with the IAM entity should have the necessary permissions to invoke the API.

AppSync supports having more than one authorizer per API and lets you granularly choose which queries, mutations, and subscriptions can be used by clients using a particular authorization method.

Data Sources

Data sources are resources that AWS AppSync can use to interact with data stores.

The amazing thing about AppSync is that the supported all direct integrations donโ€™t require a Lambda function, and therefore there no cold starts are involved.

โ€‹
AWS AppSync supports the following types of data sources:

  • Amazon DynamoDB: To read or write data directly into a DynamoDB table.
  • AWS Lambda: Run custom code in the language of your choice. This allows you to integrate with any data source of your choice (e.g. MongoDB), or execute complex and custom business logic.
  • Amazon OpenSearch/Elastic Search: Offers search engine capabilities.
  • Amazon EventBridge: To publish events directly into an event bus.
  • HTTP: Allows you to invoke any existing HTTP endpoint. It can be used for example to connect with third parties or connect legacy REST APIs to GraphQL.
  • Aurora: Provides direct access to Amazon Aurora databases (PostgreSQL, MySQL)
  • None: None is a special data source type that does not connect to any data store. You can use it to execute simple transformation logic or data formatting, for example.

Resolvers

Resolvers are a set of functions that are executed by AWS AppSync to interact with the data sources. They are the glue between the data sources and the GraphQL schema.

There are two ways to write resolvers: Velocity Template Language (VTL) and JavaScript which was introduced in late 2022. If you have never worked with VTL it can be quite, special.

One resolver is composed of two functions, also known as handlers:

  • request: This handler is executed to generate a request to the data source. e.g. a DynamoDB Query.
  • response: Executed after the data comes back from the data source. You can use it to transform the data and map it to the GraphQL schema.

AWS AppSync also supports a special kind of resolver: pipeline resolvers.

They are a sequence of different resolver functions. They can be used, for example, if you need to retrieve data from different data sources before returning it to the client.

โ€‹

Caching

One of the first steps to improve your API is to add a caching layer. AWS AppSync has built-in support for server-side caching.

A common use case is to use database responses (e.g. from DynamoDB) and save them in a key-value store like Redis. Let's say you calculate a social media feed in your application. It can make sense to save this feed to avoid unnecessary computation and load on your database.

This feature allows you to store frequent requests in a high-speed cache, allowing for a better user experience. It can also remove some load off the data sources.

โ€‹

GraphBolt

After working many years with AppSync in large teams I saw the need to build a better, and local-first UX.

This is when I've built GraphBolt.

GraphBolt is a desktop application that streamlines the process of working with AWS AppSync, making it easier to understand what is happening inside resolvers and how they interact with the data sources.

It also offers a GraphQL client that is optimized for AWS AppSync and a dashboard with metrics and statistics to help better understand how APIs behave.

You can try it out for free here. If you want to use it, you'll get 30% off with the code AWSFUNDAMENTALS.

โ€‹

Workshop

I just recently launched a free community-powered website to learn more about AppSync. You can find it at appsync.wtf. Back to you Sandro & Tobi


AWS Community Builder Applications are Open!

Ben, Tobi, and I are all part of an amazing AWS Community Builder Program. The program aims at people who are passionate about contributing to the community. The applications are currently open again. If you're interested in getting AWS News even faster, and want some cool perks like a Community, Merch, and free Courses apply here.


What do you think?

We hope Ben could give you a great overview of AppSync. Make sure to try it out to see how easy it is to build a fully-managed GraphQL API.

Have you used AppSync and GraphQL before? Are you missing any resources for trying it out?

Let us know by replying to this email. If you want to ask Ben anything, just hit him up on Twitter.


Thanks for reading!๐Ÿ‘‹๐Ÿฝ

See you in two weeks for the next services.

Sandro & Tobi โœŒ๐Ÿฝ

AWS for the Real World

Join our community of over 8,800 readers delving into AWS. We highlight real-world best practices through easy-to-understand visualizations and one-pagers. Expect a fresh newsletter edition every two weeks.

Read more from AWS for the Real World

Hey Reader First things first: we apologize for not providing updates on The CloudWatch Book for a while! ๐Ÿ˜ข Sometimes, things don't go as planned and unexpected obstacles arise. But now, we're back in action, creating videos and putting the final touches on the book's content! ๐ŸŽฅ Don't just take our word for it! As an early subscriber, here's a free video from one of our favorite chapters: Anomaly Detection ๐Ÿ› In this deep-dive, you'll learn how to detect unusual patterns in metrics without...

โŒ› Reading time: 11.5 minutes ๐ŸŽ“ Main Learning: Host Web Applications on AWS with the CloudFront Hosting Toolkit ๐Ÿ‘จ๐Ÿฝ๐Ÿ’ป GitHub Code ๐Ÿ“ Blog Post Hey Reader ๐Ÿ‘‹๐Ÿฝ Happy New Week! I (Sandro) will attend the Serverless Days in Milano next week where Jeremy Daley will hold the keynote. I look forward to meeting many of you and the overall AWS community. This week's newsletter is all about hosting your frontend on AWS. AWS launched a new way of deploying your frontend to it: The CloudFront Hosting Toolkit....

โŒ› Reading time: 7 minutes ๐ŸŽ“ Main Learning: Visual Regression Testing with AWS CloudWatch Synthetics ๐Ÿ‘จ๐Ÿฝ๐Ÿ’ป GitHub Code ๐Ÿ“ Blog Post Hey Reader Keeping your website running smoothly is important.It's also important to keep an eye on its visual appearance and that it doesn't change due to an unwanted change. AWS CloudWatch Synthetic Canaries is a tool that helps you check on your websites (and APIs!) to make sure itโ€™s working well and look as expected. In this newsletter, weโ€™re going to show you...