๐Ÿ”“ 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

We teach AWS for the real world - not for certifications. Join more than 10,500 developers learning how to build real-world applications on AWS.

Read more from AWS for the Real World

AWS FOR THE REAL WORLD โฑ๏ธ Reading time: 4 minutes ๐ŸŽฏ Main Learning: Which AWS services are worth your time and which ones to skip ๐ŸŽฌ Watch on YouTube Hey Reader ๐Ÿ‘‹๐Ÿฝ a new week, new AWS video coming out. I (Sandro) used all of my knowledge from the past six plus years building AWS solutions, ranking the services I actually use and the services I hate. For some I've changed my mind A LOT over the years (e.g. DynamoDB). Let me know what you think and check it out.Here you go AWS News But first of...

AWS FOR THE REAL WORLD โฑ๏ธ Reading time: 12 minutes ๐ŸŽฏ Main Learning: The 11 most impactful AWS releases from the past 12 months that have nothing to do with AI. ๐Ÿ“ Blog Post Hey Reader ๐Ÿ‘‹ Every re:Invent recap, every AWS blog, every newsletter from the past year has been dominated by one topic. You know which one. But while everyone was writing about agents and foundation models, the core infrastructure layer kept moving. Quiet releases. No keynote fanfare. Things that actually affect your...

AWS FOR THE REAL WORLD โฑ๏ธ Reading time: 5 minutes ๐ŸŽฏ Main Learning: Deploy AWS's open-source TEAM solution for temporary admin access with approval workflows ๐ŸŽฌ Watch on YouTube Hey Reader ๐Ÿ‘‹๐Ÿฝ I hope you had a great weekend and have a great week ahead. One thing I see over and over again in AWS setups: admin permissions are either handed out way too easily or way too hard. There is no middle ground. In other systems this was already solved. You shouldnโ€™t have to DM somebody for admin access. We...