AppSync and event-driven integration
Choose the integration contract
For ticket creation and retrieval, API Gateway with Lambda provides a conventional HTTP API. AppSync GraphQL fits clients that request selected fields from a typed graph; resolvers connect fields to sources such as DynamoDB or Lambda. AppSync Events is a separate pub/sub API for live messages, not a GraphQL query API. GraphQL subscriptions can notify clients of changes; Events clients subscribe to channels over WebSocket. Use schema validation, bounded query complexity and field/resource authorization. Choose the simplest contract that meets client needs, not every service at once.
Background jobs and durable state
A repair photo needs processing. POST /tenants/north/jobs accepts validated metadata, stores a job with status QUEUED and returns HTTP 202 plus job ID and status URL. Persist the job and an outbox event in one database transaction; a relay sends the event via EventBridge to an SQS worker queue. The worker uses a conditional update and idempotent side effects; duplicate delivery is possible. Step Functions can coordinate multiple processing steps with bounded Retry and Catch. Record terminal SUCCEEDED or FAILED and expose an authorized status endpoint. A retry of the same create request with the same idempotency key and payload returns the same job; different payload is a conflict.
Authorize live messages independently
A server can publish a minimal notification containing job ID, state version and status to an AppSync Events channel for a tenant. Verify membership at subscribe time using the configured authorization mode and onSubscribe handler. Use separate publish permission for trusted workers; a client cannot choose an arbitrary tenant channel merely because it connected successfully. AppSync GraphQL subscriptions need their own field and resolver authorization. Handle membership revocation with an explicit reauthorization/disconnect strategy; a connection is not permanent proof of access. On reconnect, fetch authorized durable state and ignore stale versions.
Failures and backpressure
If a worker times out after an external side effect, a retry may repeat that effect. Use downstream idempotency keys and reconciliation; do not promise exactly-once across systems. Set queue visibility, retry and dead-letter policy appropriate for the worker. Alarm on age of oldest message and failed jobs; limit concurrency and input sizes. Do not send sensitive photo URLs or tokens in events. The UI shows accepted, processing, failed or completed rather than declaring success at submission. Practice: drop a notification, deliver an older one, then recover by querying the job status.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
AppSync and event-driven integration — knowledge check
Distinguish identity, integration and tenant-safe resource access.
Which service supports channel-based pub/sub without GraphQL queries?
What does HTTP 202 mean in the job example?
Why write an outbox event with the job?
After reconnect, how should a client recover from missed notifications?
A worker retries after timeout. Which design helps avoid repeated effects?