Cloud platforms · AWS

Serverless API with API Gateway, Lambda, DynamoDB and Cognito

A scale-to-zero API for web and mobile apps. Cognito authenticates, API Gateway enforces, Lambda runs the business logic, DynamoDB stores state and SQS or EventBridge decouple the slow work.

A reference architecture from EITSAA, not a named client system. Service limits, prices and product features change, so confirm current details before you commit to a design.

  • ACSC Essential Eight
  • Australian Privacy Principles (APP 11)
  • SA ISMF and ACSC ISM alignment
  • Sydney (ap-southeast-2)

Architecture

Architecture diagram. Tinted boundaries show regions, accounts, networks and trust zones. Numbered arrows match the flow below.
Serverless API with API Gateway, Lambda, DynamoDB and Cognito architectureWeb and mobile apps to Amazon Cognito: sign in. Web and mobile apps to AWS WAF: HTTPS + JWT. AWS WAF to API Gateway: allowed. API Gateway to Lambda functions: invoke. Lambda functions to DynamoDB: SDK, IAM. Lambda functions to SQS and EventBridge: publish. SQS and EventBridge to Worker Lambda: poll. Lambda functions to Secrets Manager: get secretClientsAWS workload account · ap-southeast-2Public edgeApplication tier (no inbound internet)Web and mobile appsOIDC code flow + PKCEAmazon CognitoUser pool, MFA, groupsAWS WAFRate limits, managed rulesAPI GatewayREST API, JWT authoriserLambda functionsOne per bounded contextDynamoDBOn-demand, PITR, CMKSecrets ManagerThird-party credentialsSQS and EventBridgeQueues, bus, DLQWorker LambdaAsync jobs, retries1sign in2HTTPS + JWT3allowed4invoke5SDK, IAM6publish7pollget secretPlatform servicesAWS IAMAmazonCloudWatchAWS CloudTrailAWS KMS
  • People and clients
  • Security and identity
  • Network and edge
  • Compute and containers
  • Databases and data
  • Messaging, events and workflow
  • Monitoring, audit and analytics
  • Request or data flow
  • Asynchronous or optional
  • Boundary: region, account, network or trust zone

Request and data flow

  1. The client signs in with the Cognito hosted UI or your own UI using authorization code with PKCE. Cognito enforces MFA and returns short-lived JWTs.

  2. The client calls the API over HTTPS with the access token in the Authorization header. WAF is attached to the API stage.

  3. WAF applies rate-based and managed rules. Allowed requests continue to the API.

  4. API Gateway validates the JWT with a Cognito authoriser, validates the request against a JSON schema, applies throttling and invokes the integration.

  5. The function reads and writes DynamoDB using its own least-privilege execution role, with conditional writes to enforce invariants and idempotency keys for retries.

  6. Slow or fallible work (email, exports, third-party calls) is published to SQS or EventBridge rather than done in the request path.

  7. Worker functions poll the queue with partial batch responses. Poison messages go to a dead-letter queue with an alarm.

Components and why they were chosen

ComponentWhat it doesWhy this choice
Amazon Cognito user poolSign-up and sign-in, MFA, password policy, groups and federation to Entra ID or other OIDC and SAML providers.Managed identity avoids building authentication. Federation lets staff use the corporate IdP.
Amazon API Gateway (REST)Routing, authorisation, request validation, throttling, usage plans and WAF integration.REST APIs support WAF and usage plans. HTTP APIs are cheaper but lack some of these features.
AWS WAFRate limiting, managed rule groups and bot controls on the API stage.Cheap first line of defence against abuse.
AWS LambdaBusiness logic as small functions with their own IAM roles.No servers to patch and scale to zero. Per-function roles give least privilege.
Amazon DynamoDBKey-value and document store with single-digit millisecond reads at any scale.Operationally simple and elastic when access patterns are known up front.
Amazon SQS and EventBridgeQueues for buffering and an event bus for fan-out.Decoupling protects the API from slow dependencies and gives built-in retries and DLQs.
AWS Secrets ManagerStores and rotates third-party credentials.Keeps secrets out of environment variables and source control.
AWS KMSCustomer-managed key for DynamoDB, SQS and secrets.Key policy and CloudTrail give auditable control over decryption.

Design decisions and trade-offs

Compute

Lambda behind API Gateway.

Why. Spiky or low-volume workloads pay only for use and need no capacity planning.

Trade-off. Cold starts, a 15-minute limit per invocation and 29-second integration timeout on REST APIs. Sustained high volume can be cheaper on containers.

Datastore

DynamoDB with on-demand capacity and point-in-time recovery.

Why. Predictable latency and no instance to manage.

Trade-off. You model access patterns first. Ad hoc reporting needs an export to S3 and Athena, not scans.

API flavour

REST API with a JWT authoriser and schema validation.

Why. WAF, usage plans and request validation are first-class.

Trade-off. Higher per-request price than HTTP API.

Async work

SQS for work queues, EventBridge for domain events.

Why. SQS gives back-pressure and DLQs. EventBridge gives routing and schema discovery.

Trade-off. Eventual consistency means the UI must handle pending states.

Well-architected pillars

Security

JWT validation at the edge, per-function IAM roles, CMK encryption, request validation and WAF. Secrets never in code.

Reliability

Multi-AZ managed services, retries with idempotency, DLQs and PITR. Throttling protects downstream limits.

Performance

Provisioned concurrency for latency-sensitive paths, DynamoDB single-table or well-chosen keys, Lambda memory tuned with power tuning.

Cost optimisation

Per-request and per-GB-second pricing. Cost grows linearly with traffic and is easy to attribute with tags per function.

Operational excellence

Everything in IaC (CDK, SAM or Terraform), canary deployments with Lambda aliases and CodeDeploy or gradual rollouts.

Sustainability

Scale to zero and shared multi-tenant infrastructure. Right-size memory and use Graviton (arm64) where libraries allow.

Network, identity and data

Networking

Lambdas that only call AWS services need no VPC. Attach them to a VPC only to reach private resources, and then use VPC endpoints (gateway for DynamoDB and S3, interface for Secrets Manager, SQS and KMS) rather than a NAT gateway.

Identity and least privilege

Humans and machines are separate. Users are in Cognito groups mapped to scopes. Each Lambda has its own role limited to specific table ARNs and key conditions such as dynamodb:LeadingKeys for tenant isolation. Deployments use a pipeline role, never developer credentials.

Data and encryption

Classify fields at design time. Encrypt DynamoDB with a customer-managed KMS key, keep PII fields minimal, and tokenise or hash where search is not needed. Log request IDs, never payloads containing personal information.

Security and compliance mapping

ControlHow this design addresses it
Multi-factor authenticationCognito MFA for users, Identity Center MFA for administrators. Essential Eight multi-factor authentication.
Restrict administrative privilegesPer-function roles, permission boundaries and SCPs from the landing zone. Essential Eight restrict administrative privileges.
Patch applicationsManaged runtimes updated on a schedule, dependency scanning in CI. Essential Eight patch applications.
Regular backupsDynamoDB PITR and on-demand backups through AWS Backup. Essential Eight regular backups.
Personal information securityEncryption at rest and in transit, minimised retention and breach response plan. APP 11.

Mappings show how the design supports each control. They are not certifications, and EITSAA does not claim IRAP assessment or compliance for any reference architecture.

Failure modes, targets and scaling

  • Target RTOMinutes within the Region, hours for a cross-Region rebuild from IaC
  • Target RPOSeconds to minutes with PITR (restore to any second in the retention window)
  • Scaling and limitsDefault account concurrency and API throttling quotas apply; raise quotas before launch. DynamoDB item size limit is 400 KB.
Failure modeMitigation
Downstream dependency is slow or downQueue the work, apply timeouts and circuit breaking, return 202 with a status resource.
Hot partition or throttled tableHigh-cardinality partition keys, on-demand mode, adaptive capacity monitoring and write sharding if needed.
Retry storm duplicates a writeIdempotency keys stored with conditional writes. Powertools for AWS Lambda provides this pattern.
Regional event in ap-southeast-2Documented warm standby with DynamoDB global tables only when the business impact justifies the cost.

Observability and runbooks

  • Structured JSON logs with correlation IDs, CloudWatch Logs Insights and X-Ray or OpenTelemetry traces.
  • Alarms on 5xx, p95 latency, throttles, iterator age, DLQ depth and Cognito sign-in failures.
  • Dashboards per service with SLOs, and a runbook for DLQ redrive and key rotation.

Cost drivers and levers

API requests, Lambda duration and memory, DynamoDB read and write units, data transfer and WAF.

  • Move to HTTP API where WAF and usage plans are not needed.
  • Use arm64 and right-sized memory.
  • Cache read-heavy responses at API Gateway or CloudFront.
  • Use reserved capacity only once traffic is stable.

Implementation and fit

Phased approach

  1. Design access patterns and the event model before any code.
  2. Build the walking skeleton: auth, one endpoint, one table, pipeline and alarms.
  3. Add business contexts one at a time behind feature flags.
  4. Load test against quotas, then run a game day on DLQ and throttling behaviour.

Anti-patterns to avoid

  • One giant Lambda with admin permissions.
  • Full table scans for reporting.
  • Calling slow third parties synchronously.
  • Putting Lambdas in a VPC without endpoints and paying for NAT.

When to use it

  • Variable or unpredictable traffic.
  • Greenfield apps with clear access patterns.
  • Small teams that should not run servers.

When not to

  • Heavy relational reporting on the same store.
  • Long-running or GPU-bound jobs (use Fargate or Batch).
  • Teams that cannot yet manage distributed tracing and idempotency.

More in cloud platforms

Related insights

Discuss this architecture

Tell us your systems, constraints and timeline. We reply within one business day, and the initial conversation is free.