If you want a fast, reproducible way to ship static sites on AWS—complete with staging/prod, CDN, HTTPS, and custom domains—this post walks you through the exact setup I use. It’s powered by a small TypeScript AWS CDK project I maintain, which spins up the essentials (S3 + CloudFront + Route 53) and gives you simple yarn scripts to deploy. (GitHub)
staging and prod.Repo: Static Website on AWS (TypeScript CDK) → S3 bucket, CloudFront distribution, and Route 53 alias records (A & AAAA) wired up via CloudFormation. (GitHub)
AWS account with permissions to create S3, CloudFront, Route 53, and ACM.
AWS CLI installed & configured:
aws configure
AWS CDK CLI installed:
npm install -g aws-cdk
(GitHub)
git clone https://github.com/shuo-s-feng/static-website-on-aws.git
cd static-website-on-aws
yarn install
In the repo root, you’ll create two env files from .env.example:
.env.staging.env.prodPopulate them with your values:
AWS_ACCOUNT=123456789012
AWS_REGION=us-east-1
STATIC_WEBSITE_APP_NAME=StaticWebsite
# Optional, if you want a custom domain:
# STATIC_WEBSITE_DOMAIN_NAME=example.com
# STATIC_WEBSITE_DOMAIN_CERT_ARN=arn:aws:acm:us-east-1:123456789012:certificate/xxxx-xxxx-xxxx-xxxx
# Where your built site lives (e.g., Vite/NextJS export)
STATIC_WEBSITE_SOURCE_PATH=./examples/website-dist
⚠️ TLS certificate region: CloudFront requires the ACM certificate to be in us-east-1 (N. Virginia), even if your stack is elsewhere. Request or import it there. (AWS Documentation)
Staging:
yarn deploy-web:staging
Production:
yarn deploy-web:prod
These scripts synthesize and deploy the CDK stacks using the environment-specific vars above. After a successful deploy you’ll have:
Using a DNS provider other than Route 53? You’ll typically:
- Use CNAME for subdomains (e.g.,
www.example.com → dxxxxx.cloudfront.net)- Use your provider’s ALIAS/ANAME feature for the apex (
example.com) if available, since DNS standards don’t allow CNAMEs at apex. (When you’re on Route 53, the “Alias to CloudFront” A/AAAA records solve this directly.) (AWS Documentation)
Certificate not showing up for CloudFront:
Ensure the ACM cert is in us-east-1. That’s the only region CloudFront will look in for viewer-facing certs. (AWS Documentation)
Can’t point apex domain to CloudFront with CNAME:
Use Route 53 Alias A/AAAA records, or your non-AWS DNS provider’s equivalent ALIAS/ANAME feature for apex. (AWS Documentation)
New deploy but old content appears:
Invalidate the changed paths in CloudFront—or rely on content-hashed filenames so you rarely need invalidations. (AWS Documentation)
I like Netlify/Vercel/Amplify for many cases. This template is for teams that prefer:
If you need a simple, auditable way to ship static sites on AWS, this CDK template gives you a crisp starting point: configure two .env files, run one command, and you’re live behind CloudFront with HTTPS and (optionally) your own domain. Start here, then layer on SPA rewrites, CI/CD, and stricter policies as you grow. Repo link again for convenience: static-website-on-aws. (GitHub)
us-east-1. (AWS Documentation)