AWS AppSync connects applications to data through GraphQL APIs and delivers real-time events through Event APIs.
AWS AppSync basics
AWS AppSync provides managed GraphQLA language for API requests and data changes that lets clients specify the data they need. APIs for accessing application data and Event APIs for publishing and subscribingA way for a client to receive updates; GraphQL subscriptions in AppSync respond to mutations. to real-time events. It helps applications retrieve data from several sources or deliver updates to connected clients.
How it works
- Choose a GraphQL API when clients need to request selected data from data sourcesA resource or endpoint an AppSync API uses to access or process data..
- Choose an Event API when publishers send events to channelsAn AppSync Events route that delivers published events to subscribed clients. and subscribers receive them over WebSocketsA protocol for a stateful, two-way connection between client and server.. Publishers can use HTTP or WebSockets.
- For a REST API, Amazon API Gateway provides HTTP methods and stateless requests. API Gateway also offers a separate WebSocket API type.
Exam cues
- If the question says a mobile app needs data from several sources through a GraphQL endpoint, think AWS AppSync, because one API can access those sources.
- If the question says connected clients need published events, think an AppSync Event API, because clients can subscribe to channels over WebSockets.
- If the question says a REST API uses HTTP methods, think Amazon API Gateway, because its REST APIs use those methods.
Remember
- AppSync provides GraphQL APIs and Event APIs.
- Event API publishers can use HTTP or WebSockets. Subscribers use WebSockets.
Trap: API Gateway also has WebSocket APIs. A WebSocket requirement alone does not make AppSync the only choice.
From the AWS docs (8)
- AWS AppSync provides serverless GraphQL and publish-subscribe APIs.
- An AppSync GraphQL API can access multiple data sources through one endpoint.
- GraphQL lets a client specify the data it needs.
- An AppSync Event API accepts published events over HTTP or WebSocket.
- An AppSync Event API lets clients subscribe to events over WebSockets.
- An AppSync Events channel routes published events to clients subscribed to that channel.
- Amazon API Gateway REST APIs use HTTP methods and stateless client-server communication.
- Amazon API Gateway also supports WebSocket APIs with stateful two-way communication.
GraphQL APIs and real-time data
An AWS AppSync GraphQLA language for API requests and data changes that lets clients specify the data they need. API gives clients a way to request selected data from several sources. A schemaThe definition of the shape of data available through a GraphQL API. describes the available data, while resolversCode attached to a GraphQL schema field that determines how to resolve that field. handle the fields in a request.
How it works
- Define a schema for the data clients can request. Clients choose the fields they need.
- Attach resolvers to fields. A resolver processes the request and obtains data from a data sourceA resource or endpoint an AppSync API uses to access or process data. when needed.
- Connect data sources such as Amazon DynamoDB, AWS Lambda, HTTP endpoints, Amazon OpenSearch Service or relational databases.
- Choose authorization for the API. Options include API keys, AWS Identity and Access Management (IAM), Amazon Cognito user pools, OpenID Connect and AWS Lambda.
- For live updates, link a subscriptionA way for a client to receive updates; GraphQL subscriptions in AppSync respond to mutations. to a mutationA GraphQL operation that describes a change to data.. AppSync maintains a WebSocketA protocol for a stateful, two-way connection between client and server. connection for the subscribing client and delivers updates when the mutation triggers the subscription.
- Enable server-side caching when repeated requests benefit from data held in memory. Per-resolver caching requires enabling each resolver.
Exam cues
- If the question says a mobile app needs data from multiple sources through one GraphQL endpoint, think AWS AppSync, because it can connect those sources to one API.
- If the question says a web app needs live updates after GraphQL mutations, think AppSync subscriptions, because mutations trigger them over managed WebSocket connections.
- If the question says a GraphQL API needs to read and write DynamoDB items, think AppSync resolvers, because they can use GetItem and PutItem.
- If the question says an AppSync custom domain needs HTTPS, think an ACM certificate in us-east-1 and DNS to CloudFront, because AppSync uses a CloudFront distribution for the domain.
- If the question says repeated requests should reduce data source access, think AppSync caching, because cached data is held in memory.
Remember
- A schema describes data; resolvers handle fields and can access data sources.
- GraphQL subscriptions respond to mutations. Direct data source changes alone do not trigger them.
- API keys suit development or APIs that can safely be public.
Trap: An AppSync GraphQL subscription does not automatically observe every direct database change. It responds to its linked mutation.
From the AWS docs (19)
- A GraphQL schema defines the shape of the data available to clients.
- GraphQL clients can specify the data they need in a request.
- An AppSync GraphQL API can access multiple data sources through one endpoint.
- An AppSync resolver is code attached to a schema field that determines how to resolve the field.
- Amazon DynamoDB is a supported AppSync GraphQL data source.
- AWS Lambda is a supported AppSync GraphQL data source.
- HTTP endpoints are supported AppSync GraphQL data sources.
- Amazon OpenSearch Service is a supported AppSync GraphQL data source.
- AppSync GraphQL APIs support relational databases as data sources.
- GraphQL mutations describe changes to data.
- AppSync GraphQL subscriptions are triggered by mutations.
- AppSync establishes and maintains a WebSocket connection when a client invokes a GraphQL subscription.
- AppSync GraphQL subscriptions are triggered by mutations rather than arbitrary changes to the data source.
- An AppSync GraphQL API can authorize requests with Amazon Cognito user pools, IAM, OpenID Connect, a Lambda authorizer or an API key.
- AppSync API keys are intended for development or APIs that can safely be public.
- AppSync server-side caching stores data in memory to reduce direct access to data sources.
- AppSync per-resolver caching requires each cached resolver to be explicitly enabled.
- AppSync DynamoDB pipeline resolvers can use GetItem to read and PutItem to write items.
- An AppSync custom domain needs an ACM certificate covering the name in us-east-1 and a DNS record pointing to its CloudFront distribution.
Flashcards
Nothing to review here right now. Pick other topics or another filter.
All 11 cards as a list
A mobile app needs one managed GraphQL endpoint for data from several sources. Which AWS service fits?
AWS AppSync. Its GraphQL API can access multiple data sources through one endpoint.
A web app needs to publish events and deliver them to subscribed clients over WebSockets. Which AWS AppSync API fits?
An AppSync Event API. Clients subscribe to channels to receive published events.
How does an AWS AppSync GraphQL API differ from an Amazon API Gateway REST API?
GraphQL lets clients specify the data they need. API Gateway REST APIs use HTTP methods and stateless communication.
Does choosing Amazon API Gateway rule out WebSocket APIs when comparing it with AWS AppSync?
No. API Gateway also offers WebSocket APIs for stateful two-way communication.
What do a schema and a resolver do in an AWS AppSync GraphQL API?
The schema defines the data shape. A resolver handles how a field is resolved.
A web app using AWS AppSync must receive live updates after its users change data through GraphQL. What should it use?
GraphQL subscriptions tied to mutations. AppSync maintains the client WebSocket connection.
Will every direct database change automatically trigger an AWS AppSync GraphQL subscription?
No. AppSync GraphQL subscriptions are triggered by mutations. A direct data source change alone is not a GraphQL mutation.
Which authorization modes can protect an AWS AppSync GraphQL API?
API keys, AWS Lambda, AWS IAM, OpenID Connect and Amazon Cognito user pools.
An AWS AppSync GraphQL API repeatedly reads the same data. What feature can reduce direct data source access?
Server-side caching. It stores data in memory; per-resolver caching requires opting in each resolver.
Can AWS AppSync DynamoDB resolvers read and write items?
Yes. Resolver functions can use GetItem and PutItem.
What certificate and DNS setup does an AWS AppSync custom domain need?
Use an ACM certificate covering the name in us-east-1 and point DNS to the AppSync CloudFront distribution.