Skip to content

Latest commit

 

History

History
123 lines (90 loc) · 3.24 KB

File metadata and controls

123 lines (90 loc) · 3.24 KB

AppSync & Amplify

AppSync — Managed GraphQL

What Is It?

AppSync is a managed GraphQL API service. Instead of REST endpoints, clients query exactly what data they need. Real-time subscriptions built-in.

Real-World: A React app needs user profile + their recent orders + order items. With REST: 3 API calls. With GraphQL/AppSync: 1 query returns exactly what's needed.

query {
  user(id: "123") {
    name
    email
    orders(limit: 5) {
      id
      total
      items {
        name
        price
      }
    }
  }
}

Data Sources

AppSync resolvers connect to data sources:

Data Source Example
DynamoDB User profiles, product catalog
Lambda Complex business logic, external APIs
RDS (Aurora Serverless) Relational data
HTTP REST APIs, third-party services
ElasticSearch/OpenSearch Full-text search
None Local resolvers, static responses

Real-Time Subscriptions

subscription OnOrderUpdate {
  onUpdateOrder(customerId: "cust_123") {
    id
    status
    updatedAt
  }
}

Client subscribes via WebSocket → when DynamoDB item updates → AppSync pushes to subscribed clients.

Real-World: Order tracking page updates automatically when order status changes.


Caching

AppSync has server-side caching:

  • Cache entire API responses or per-resolver
  • TTL configurable
  • Reduce calls to DynamoDB/Lambda

Cognito Integration

type Query {
  getMyOrders: [Order] @aws_cognito_user_pools  # Only authenticated users
  getPublicProducts: [Product]  # Anyone
}

AppSync validates Cognito JWT automatically.


Exam Tips

  1. AppSync = GraphQL + Real-time subscriptions. REST API = API Gateway.
  2. AppSync + DynamoDB: direct integration without Lambda for simple CRUD.
  3. Real-time = subscriptions via WebSocket. API Gateway also has WebSocket — but AppSync is managed and GraphQL-specific.
  4. AppSync Offline: via Amplify DataStore — synchronizes local data when connection restored.

Amplify

What Is It?

Amplify is a full-stack development platform — CLI, libraries, and hosting for web/mobile apps. It provisions AWS services automatically.

Key Features

  • amplify add auth → provisions Cognito User Pool
  • amplify add api → provisions AppSync or API Gateway
  • amplify add storage → provisions S3
  • amplify hosting → CloudFront + S3 static hosting
  • amplify add predictions → Rekognition, Polly, Translate

Real-World: Mobile developer runs amplify initamplify add authamplify add apiamplify push → entire backend created. Frontend library connects everything.

Amplify DataStore

Offline-first data sync:

import { DataStore } from 'aws-amplify';
import { Order } from './models';

// Works offline, syncs to AppSync/DynamoDB when online
const orders = await DataStore.query(Order, o => o.status('eq', 'PENDING'));

Exam Tips

  1. Amplify is the full-stack framework (CLI + libraries). AppSync is the managed GraphQL service.
  2. Amplify Hosting = CI/CD + hosting for frontend apps (like Vercel/Netlify but on AWS).
  3. For exam: if question mentions "mobile app + offline sync" → Amplify DataStore + AppSync.