Static Site (CloudFront + S3)

beginner

CloudFront distribution with S3 origin and Origin Access Control, HTTPS redirect, security headers, SPA error routing, and optional custom domain with ACM + Route53.

Quick Start

Via CLI (recommended)

npx cdk-starter create

Then select "Static Site (CloudFront + S3)" from the prompt

Or scaffold directly

npx cdk-starter create --starter static-site

README

Static Site (CloudFront + S3)

CloudFront distribution with S3 origin, Origin Access Control, HTTPS redirect, security response headers, and SPA 404→index.html routing.

Custom domain (optional)

Set domainName and hostedZoneDomain in bin/app.ts:

new StaticSiteStack(app, 'StaticSiteStack', {
  domainName: 'www.example.com',
  hostedZoneDomain: 'example.com',
});

CDK will provision an ACM certificate and Route53 alias record automatically.

Deploy your site

Put your built frontend files in site/, then deploy:

npx cdk deploy

CloudFront cache is automatically invalidated on each deploy.

Prerequisites

  • Node.js ≥ 20
  • AWS CLI configured (aws configure)
  • CDK bootstrapped (npx cdk bootstrap)

Deploy

npm install
npx cdk diff
npx cdk deploy

Tear down

npx cdk destroy