Skip to Content

Serverless mobile app: MyTodoList

A serverless REST API for a mobile app with API Gateway, Lambda and DynamoDB, sign-in with Cognito, direct per-user access to S3 with temporary credentials, and read caching with DAX and API Gateway.

The app

MyTodoList is a mobile to-do app. The requirements:

  • expose a REST API over HTTPS;
  • a serverless architecture;
  • users interact directly with their own folder in S3;
  • users sign in through a managed serverless service;
  • users write and read to-dos, but mostly read them;
  • the database must scale and give high read throughput.

MyTodoList serverless mobile app: the app signs in with Amazon Cognito, which also gives it temporary AWS credentials to read and write its own folder in Amazon S3; it calls a REST API on API Gateway over HTTPS, which verifies the Cognito token, caches responses and invokes Lambda; Lambda queries DynamoDB through a DAX cache for microsecond reads MyTodoList serverless mobile app: the app signs in with Amazon Cognito, which also gives it temporary AWS credentials to read and write its own folder in Amazon S3; it calls a REST API on API Gateway over HTTPS, which verifies the Cognito token, caches responses and invokes Lambda; Lambda queries DynamoDB through a DAX cache for microsecond reads

No servers to manage, from sign-in to database.

The REST API layer

  • The app calls API Gateway over HTTPS.
  • API Gateway invokes Lambda functions that run the logic.
  • Lambda queries DynamoDB, which scales without servers.
  • Users sign in with Amazon Cognito user pools; API Gateway verifies the token on each call (a Cognito authorizer).

Giving users access to S3

Users upload and download their files straight to S3, without going through the API:

  1. The app signs the user in with Cognito.
  2. A Cognito identity pool exchanges the sign-in for temporary AWS credentials (through STS) tied to an IAM role.
  3. The role's policy only allows the user's own prefix, with the policy variable ${cognito-identity.amazonaws.com:sub}, for example arn:aws:s3:::mytodolist-files/${cognito-identity.amazonaws.com:sub}/*.

The same pattern gives users direct, restricted access to DynamoDB (fine-grained access by partition key) or Lambda.

High read throughput

  • DAX sits in front of DynamoDB and caches reads in memory: microsecond reads, fewer read capacity units, and no code change beyond the DAX client.
  • API Gateway caching stores whole responses for a TTL (default 300 seconds, up to 3,600), so repeated requests never reach Lambda. It's a good fit for answers that change slowly and are the same for many users.

What this lecture covered

  • A serverless REST API: HTTPS, API Gateway, Lambda, DynamoDB.
  • Cognito generating temporary credentials to reach an S3 bucket with a restricted policy: app users access AWS resources directly. The pattern also works for DynamoDB and Lambda.
  • Caching reads on DynamoDB with DAX.
  • Caching REST requests at the API Gateway level.
  • Authentication and authorization with Cognito.

Real-world examples

  • A note-taking app with 2 million users stores attachments under s3://notes-files/<identity-id>/, uploaded directly by the app with Cognito credentials; the API only stores metadata in DynamoDB.

Exam tips

  • "Mobile app users upload to their own folder in S3" → Cognito identity pool + IAM policy with ${cognito-identity.amazonaws.com:sub}.
  • "Sign-in for a mobile or web app, serverless" → Cognito user pools.
  • "Read-heavy DynamoDB, microsecond latency" → DAX.
  • "Same responses requested again and again through API Gateway" → API Gateway caching.

Common traps

  • "Embed an IAM user's access keys in the mobile app." Never: keys can be extracted. Use Cognito temporary credentials.
  • "Proxy all file uploads through API Gateway and Lambda." It works for small files but adds cost and limits (10 MB payloads on REST APIs); upload straight to S3.
  • "DAX speeds up writes." It caches reads; writes go through to DynamoDB.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt