Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSMessaging

AWS AppSync

Managed GraphQL and Event API service — query multiple data sources with a single endpoint, real-time subscriptions via WebSockets, and built-in offline sync.

Key point

  • AWS AppSync is a managed GraphQL API service — a single endpoint that lets clients query exactly the data they need from multiple backends (DynamoDB, Lambda, RDS, HTTP, OpenSearch) in one request.
  • Key differentiator vs API Gateway: GraphQL (flexible queries, no over-fetching), built-in real-time subscriptions (WebSocket managed by AWS), and offline sync for mobile/web clients.

Overview

AWS AppSync is a fully managed service for building GraphQL and Event APIs — it provides a single endpoint to query, mutate, and subscribe to data from multiple sources with built-in real-time updates, caching, and offline synchronisation for mobile and web applications.


Core Concepts

ConceptDescription
GraphQL SchemaDefines types, queries, mutations, and subscriptions — the contract between client and API
QueryRead operation — clients request exactly the fields needed, avoiding over-fetching
MutationWrite operation — create, update, or delete data in backend sources
SubscriptionReal-time push via WebSocket — clients receive updates when data changes
ResolverMaps a GraphQL field to a data source — contains request and response mapping templates
Pipeline ResolverChains multiple functions (resolvers) in sequence for complex operations
Data SourceBackend that AppSync connects to: DynamoDB, Lambda, RDS (Aurora), HTTP endpoint, OpenSearch, EventBridge
Merged APICombines multiple AppSync source APIs into a single endpoint for federated GraphQL
Event APIPub/sub API for real-time event broadcasting — publish and subscribe without GraphQL schema
CachingOptional server-side cache (ElastiCache-backed) to reduce resolver invocations
Conflict DetectionVersioned data sync for offline clients — detects and resolves write conflicts automatically

How AppSync Works

Client (Web / Mobile / IoT)
    → AppSync Endpoint (single GraphQL URL)
        → Schema + Resolvers
            ├── DynamoDB (direct resolver — no Lambda needed)
            ├── Aurora Serverless (RDS Data API)
            ├── Lambda (custom business logic)
            ├── HTTP Endpoint (any REST API)
            ├── OpenSearch (full-text search)
            └── EventBridge (emit events)
        ← Aggregated response (exactly the fields requested)

Real-time:
    Client ←── WebSocket ←── AppSync Subscription
                              (triggered by mutations)

Data Sources

Data SourceUse CaseResolver Type
Amazon DynamoDBPrimary NoSQL data store — direct CRUD without LambdaVTL or JS runtime
AWS LambdaCustom business logic, external API calls, transformsVTL or JS runtime
Amazon RDSRelational queries via Aurora Serverless Data APIVTL or JS runtime
HTTP EndpointProxy to any REST API or microserviceVTL or JS runtime
Amazon OpenSearchFull-text search and analytics queriesVTL or JS runtime
Amazon EventBridgeEmit events to EventBridge from mutationsVTL or JS runtime
NoneLocal resolver — transform data without a backend callVTL or JS runtime

AppSync vs API Gateway

CriteriaAppSyncAPI Gateway
API styleGraphQL (single endpoint, flexible queries)REST / HTTP (resource-based, fixed endpoints)
Data fetchingClient selects exact fields — no over-fetchingServer defines response shape per endpoint
Multiple data sourcesSingle query resolves across multiple backendsOne integration per endpoint
Real-timeBuilt-in subscriptions (managed WebSocket)WebSocket API (manual connection management)
Offline syncBuilt-in conflict detection and resolutionNot supported
CachingOptional (dedicated cache instance)Built-in (REST API only)
Auth optionsAPI key, Cognito, IAM, OIDC, Lambda authorizerAPI key, Cognito, IAM, JWT, Lambda authorizer
Throttling / API keysRate limiting via WAF; API keys for auth onlyBuilt-in usage plans + API keys
Best forData-rich apps, real-time dashboards, mobile syncREST APIs, serverless backends, AWS service proxy

Authorization Methods

MethodDescription
API KeySimple token for public or development access (expiry up to 365 d)
Amazon CognitoUser pool-based auth — group-level and field-level access control
IAMSigV4 signing — for server-to-server or AWS service calls
OIDCAny OpenID Connect-compliant identity provider
Lambda AuthorizerCustom auth logic (OAuth, SAML, custom tokens)

AppSync supports multiple auth modes on a single API — different types or fields can use different auth methods.


Real-time Subscriptions

1. Client subscribes:    subscription { onCreateMessage { id text } }
2. Another client mutates: mutation { createMessage(text: "hello") { id } }
3. AppSync pushes update via WebSocket to all subscribed clients
  • Managed WebSocket connection — no infrastructure to maintain.
  • Subscriptions are triggered by mutations defined in the schema.
  • Scales to millions of concurrent connections.
  • Secured by the same auth methods as queries and mutations.

Offline and Conflict Resolution

FeatureDescription
Offline supportAmplify DataStore caches data locally; queues mutations while offline
Conflict detectionVersioned records detect concurrent writes from multiple offline clients
Resolution strategyAuto-merge, optimistic concurrency, Lambda-based custom resolution

SAA/SAP Tip: "Mobile app that works offline and syncs when back online" → AWS AppSync with Amplify DataStore. API Gateway does not have built-in offline sync or conflict resolution.


Common Use Cases

  • Data-rich mobile/web apps — Single GraphQL endpoint aggregates data from DynamoDB, RDS, and external APIs in one query.
  • Real-time dashboards — Subscriptions push live updates (scores, stock prices, IoT telemetry) to connected clients via WebSocket.
  • Offline-first mobile apps — Amplify DataStore + AppSync sync data when connectivity resumes with conflict resolution.
  • Federated API — Merged API combines multiple team-owned AppSync APIs into a single company-wide GraphQL endpoint.
  • AI gateway — AppSync resolves queries to Amazon Bedrock for generative AI responses integrated with application data.

SAA/SAP Exam Tips

SAA Tip: "GraphQL API" or "single endpoint to query multiple data sources" → AWS AppSync. API Gateway is REST/HTTP — not GraphQL.

SAA Tip: "Real-time updates pushed to clients" + "managed WebSocket" → AppSync subscriptions. API Gateway WebSocket API requires manual connection management.

SAP Tip: AppSync resolvers can connect directly to DynamoDB without Lambda in between. This reduces latency and cost for simple CRUD operations. Use Lambda resolvers only when custom business logic is needed.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAWS AppSyncBaseline
AzureAzure API Management (GraphQL pass-through)No fully managed GraphQL service
GCPApigee + custom GraphQL serverNo native managed GraphQL
On-PremisesApollo Server, Hasura, GraphQL YogaOpen-source GraphQL servers and gateways

Pricing Model

DimensionUnitNotes
Query and mutation requests$4.00 per millionPer 5 KB payload
Real-time updates$2.00 per millionOutbound messages and WebSocket operations
Connection minutes$0.08 per million minCharged while clients are connected via WebSocket
Event API operations$1.00 per millionPublish, subscribe, and broadcast operations
CachingPer instance hourOptional — instance sizes from cache.small upward

Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page