profile

AWS for the Real World

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

Published about 1 month agoย โ€ขย 5 min read

๐Ÿ‘€ 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

by Tobi & Sandro

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

Hi Reader ๐Ÿ‘‹๐Ÿฝ This week, we're diving headfirst into the deep end of AWS's pool of innovations with the IAC Generator โ€” a tool that's been causing quite the buzz. The promise AWS gives us is quite bold: Generate AWS CloudFormation templates and AWS CDK apps for existing AWS resources in minutes. But does it really work? Let's find out together. This will be a hands-on ๐Ÿ‘ท๐Ÿฝโ€โ™€๏ธ issue. For the impatient, TL;DR, in a nutshell, ๐Ÿฅœ: Good for a start, but far away from usable in production. The...

6 days agoย โ€ขย 5 min read

This is not properly displayed? Read all of our issues online! ๐Ÿ’ก Hi Reader ๐Ÿ‘‹๐Ÿฝ We've said it more than once and we still stand with it: AWS IAM is the most complete but still underlooked service out there. Overwhelmingly, engineers look at the way of least resistance via "Which permissions do I have to grant to make this work? ๐Ÿค”" or directly using wildcards for actions and resources on all policies, instead of diving into all the aspects of the service and its possibilities. Nevertheless, it's...

21 days agoย โ€ขย 4 min read

Hey Reader, amazing that you're interested in creating the CloudWatch Book together with us. This is the third CloudWatch Update. Coincidentally, Sandro (I'm writing this update) turned 30 last week ๐Ÿฅณ In this update, we'll introduce you to our newly created web application: The GitHub Repository Tracker. While it is not the fanciest name it, the project will help you a lot in learning & understanding CloudWatch for the real world. We thought it would be much easier to show it in a video so...

29 days agoย โ€ขย 6 min read
Share this post