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.
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:
- The app signs the user in with Cognito.
- A Cognito identity pool exchanges the sign-in for temporary AWS credentials (through STS) tied to an IAM role.
- The role's policy only allows the user's own prefix, with the policy variable
${cognito-identity.amazonaws.com:sub}, for examplearn: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
Sign users in with Cognito, use an identity pool to give them temporary credentials for an IAM role, and restrict the role's S3 policy to the prefix ${cognito-identity.amazonaws.com:sub}/. The app uploads directly to S3.
Put DAX in front of the table so the hot items are served from memory, and turn on API Gateway caching for responses that don't change per user.
AWS documentation
WordPress and fast launches: MyWordPress.com
A scalable WordPress site with Aurora and EFS for shared images, why EBS doesn't work across instances, how to launch apps quickly with golden AMIs, user data and snapshots, and the typical 3-tier web architecture.
Serverless website: MyBlog.com
A global serverless blog with CloudFront and S3 for static files, a public API on API Gateway and Lambda, DAX and DynamoDB global tables, a welcome email through DynamoDB Streams and SES, and thumbnails from S3 events.