Skip to main content

AWS AppSync

Core concept: AppSync is a fully managed GraphQL API service β€” ideal for real-time, multi-data-source, and mobile/web apps.


AppSync vs API Gateway

FeatureAppSyncAPI Gateway
ProtocolGraphQLREST / HTTP / WebSocket
Real-timeβœ… Native subscriptions (WebSocket)WebSocket API only
Multiple data sourcesβœ… Single query, multiple sources❌ One integration per endpoint
Offline syncβœ… Conflict resolution built-in❌
Cachingβœ… Server-side per-resolverβœ… Stage-level
Use caseMobile/web apps, real-time dashboardsREST APIs, microservices

Data Sources

SourceDescription
DynamoDBDirect DynamoDB access via VTL mapping
LambdaAny custom logic, any backend
RDS / Aurora ServerlessSQL queries via Data API
OpenSearchFull-text search
HTTPAny REST API
NoneLocal resolvers (computed values)

Resolvers

Resolvers map GraphQL operations to data source operations using VTL (Velocity Template Language) or JavaScript (APPSYNC_JS):

// JavaScript resolver β€” DynamoDB GetItem
export function request(ctx) {
return {
operation: 'GetItem',
key: util.dynamodb.toMapValues({ id: ctx.args.id })
};
}

export function response(ctx) {
return ctx.result;
}

Pipeline Resolvers

Chain multiple data sources in one resolver:

Query: getOrderWithProducts
β†’ Step 1: DynamoDB (get order)
β†’ Step 2: DynamoDB (get product details)
β†’ Step 3: Lambda (calculate price with tax)
β†’ Return merged result

Real-Time Subscriptions

# Schema
type Subscription {
onOrderUpdated(customerId: ID!): Order
@aws_subscribe(mutations: ["updateOrder"])
}

# Client subscribes via WebSocket
subscription {
onOrderUpdated(customerId: "CUST-123") {
orderId
status
updatedAt
}
}
  • Client connects over WebSocket (MQTT over WebSocket)
  • AppSync pushes updates automatically when mutation fires

Authorization Modes

ModeUse Case
API KeyPublic APIs, development
AWS IAMServer-to-server, IAM roles
Cognito User PoolsUser authentication (most common)
OIDCThird-party identity providers
Lambda AuthorizerCustom auth logic

Multiple modes can be configured simultaneously, with one as default.


Caching

Per-resolver TTL: 0 – 3600 seconds
Cache key: resolved query arguments

Enables: Cache frequently-requested data
Reduces: Lambda invocations, DynamoDB reads

DVA-C02 Exam Tips

Quick Exam Rules
  • AppSync vs API Gateway: If you need real-time WebSocket Subscriptions natively tied to data changes, choose AppSync. If you need simple REST API microservices, choose API Gateway.
  • Data Source unification: AppSync allows a single GraphQL endpoint to aggregate data from DynamoDB, RDS, and Lambda simultaneously.
  • Resolvers: Use Pipeline Resolvers to sequence operations across multiple data sources.

Practice Questions

Q1. A mobile app needs real-time order status updates pushed to connected clients whenever an order is updated. Which service is BEST suited?

A) API Gateway WebSocket API
B) SQS + client polling
C) AppSync with GraphQL Subscriptions
D) SNS mobile push notifications

βœ… Answer & Explanation

C β€” AppSync Subscriptions automatically push mutation events to connected WebSocket clients β€” purpose-built for this pattern. API Gateway WebSocket requires managing connection IDs and routing manually.


Q2. A single GraphQL query needs to aggregate data from DynamoDB and call a Lambda for business logic. Which AppSync feature enables this without client-side orchestration?

A) Multiple AppSync APIs
B) Pipeline Resolver chaining DynamoDB and Lambda functions
C) Lambda resolver that calls DynamoDB
D) REST API Gateway passthrough

βœ… Answer & Explanation

B β€” Pipeline Resolvers chain multiple resolver functions (each connecting to a different data source) into a single GraphQL operation. The client makes one request; AppSync orchestrates the steps.


Resources

πŸ“–
Track Page Progress0 / 635 Read
Knowledge Base Completion0%