Skip to Content

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

MyBlog.com serverless website: browsers get static files from CloudFront, which reads a private S3 bucket through Origin Access Control, with a bucket policy that allows only that distribution; dynamic requests go to a REST API on API Gateway, which invokes Lambda to query DynamoDB global tables through a DAX cache MyBlog.com serverless website: browsers get static files from CloudFront, which reads a private S3 bucket through Origin Access Control, with a bucket policy that allows only that distribution; dynamic requests go to a REST API on API Gateway, which invokes Lambda to query DynamoDB global tables through a DAX cache

Static files from the edge, data from a global table.
  • 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

The welcome email flow: a new user item in the DynamoDB users table appears in the DynamoDB Stream, which invokes a Lambda function whose IAM role allows it to call Amazon SES, and SES sends the new user a welcome email The welcome email flow: a new user item in the DynamoDB users table appears in the DynamoDB Stream, which invokes a Lambda function whose IAM role allows it to call Amazon SES, and SES sends the new user a welcome email

React to a new item, send an email.
  • 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

The thumbnail flow: the browser uploads a photo to an S3 bucket, through CloudFront for faster uploads; the S3 event invokes a Lambda function that writes a thumbnail to a second bucket, whose events can also go to SQS or SNS The thumbnail flow: the browser uploads a photo to an S3 bucket, through CloudFront for faster uploads; the S3 event invokes a Lambda function that writes a thumbnail to a second bucket, whose events can also go to SQS or SNS

Every upload triggers its own thumbnail.
  • 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-1 and eu-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

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