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.
The app
MyBlog.com must:
- scale globally;
- serve blogs that are rarely written but often read;
- serve some of the site as static files and the rest through a dynamic REST API;
- cache wherever possible;
- send every new subscriber a welcome email;
- generate a thumbnail for every photo uploaded to the blog.
Static content and the API
- Static content, globally: CloudFront in front of an S3 bucket caches the files in edge locations around the world.
- Securely: the bucket stays private. CloudFront reads it with Origin Access Control (OAC), and the bucket policy only allows that CloudFront distribution.
- A public REST API: API Gateway → Lambda → DAX → DynamoDB. The API is public, so it needs no Cognito.
- Globally: DynamoDB global tables replicate the data to several Regions, so reads are local everywhere. (Aurora Global Database would also work for a relational model.)
The welcome email flow
- A new subscriber is a new item in the users table.
- DynamoDB Streams records the change and invokes a Lambda function.
- The function's IAM role allows it to use Amazon SES, which sends the email, with no mail server to run.
The thumbnail flow
- Photos are uploaded to S3, directly or through CloudFront (or S3 Transfer Acceleration) for faster uploads from far away.
- An S3 event notification invokes Lambda, which resizes the image and writes the thumbnail to another bucket (writing back to the same prefix would trigger the function again).
- The thumbnail bucket's own events can notify SQS or SNS (optional), for example to update a search index.
Summary
- Static content is distributed with CloudFront and S3.
- The REST API is serverless, and public, so it doesn't need Cognito.
- A global DynamoDB table serves the data worldwide (Aurora Global Database is an alternative).
- DynamoDB Streams triggers a Lambda function, whose IAM role lets it use SES to send emails serverlessly.
- S3 can trigger SQS, SNS or Lambda to react to events.
Real-world examples
- A recipe blog serves its pages from CloudFront and S3 at a few dollars a month, and its search and comments API from Lambda and a DynamoDB global table in
us-east-1andeu-west-1.
Exam tips
- "Static website, global, secure, S3 not public" → CloudFront + S3 with OAC and a bucket policy for the distribution.
- "Send an email when an item is added to DynamoDB" → DynamoDB Streams → Lambda → SES.
- "Process images when they're uploaded" → S3 event notification → Lambda.
- "Low-latency reads worldwide, NoSQL" → DynamoDB global tables.
Common traps
- "Make the bucket public for CloudFront." Use OAC and keep Block Public Access on.
- "Write thumbnails to the same bucket and prefix that triggers the function." That creates an endless loop; use another bucket or a filtered prefix.
Check yourself
Create a CloudFront distribution with the bucket as origin and Origin Access Control, update the bucket policy to allow only that distribution, and turn on Block Public Access.
Turn on DynamoDB Streams for the table, add a Lambda trigger that filters for new items, and give the function an IAM role that allows ses:SendEmail.
AWS documentation
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.
Microservices and offloading downloads
A microservice architecture where each service is built its own way, synchronous and asynchronous patterns between services, their challenges, and how adding CloudFront offloads software update downloads from EC2.