One-Command Static Website Deployment on AWS (with CDK)

8/24/2025

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)

What you get

  • Infrastructure as Code (TypeScript / CDK). One codebase, repeatable deploys.
  • Two environments by default: staging and prod.
  • Global CDN with HTTPS: CloudFront in front of S3 for speed and security.
  • Custom domain ready: Route 53 A/AAAA alias records when you use hosted zones in AWS. (GitHub, AWS Documentation)

Repo: Static Website on AWS (TypeScript CDK) → S3 bucket, CloudFront distribution, and Route 53 alias records (A & AAAA) wired up via CloudFormation. (GitHub)

Prereqs (5 minutes)

  • 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)

Clone & install

git clone https://github.com/shuo-s-feng/static-website-on-aws.git
cd static-website-on-aws
yarn install

Configure environments

In the repo root, you’ll create two env files from .env.example:

  • .env.staging
  • .env.prod

Populate 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)

Deploy

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:

  • CloudFormation stack(s) managing everything
  • S3 bucket with your static assets
  • CloudFront distribution (global CDN + HTTPS)
  • Route 53 alias records (A/AAAA) pointing your domain to CloudFront (if domain is configured in the env file) (GitHub, AWS Documentation)

Accessing your site

  • Via CloudFront (assigned domain in the AWS Console)
  • Via your custom domain (if configured) using Route 53 alias records to the distribution. Aliases work for root (apex) and subdomains—unlike CNAMEs at apex. (AWS Documentation)

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)

Common pitfalls & fixes

  • 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)

Why this stack (and not )

I like Netlify/Vercel/Amplify for many cases. This template is for teams that prefer:

  • Pure AWS control plane (security, cost, IAM, private S3, etc.)
  • IaC first: reproducible environments, easy PR reviews on infra changes
  • Zero runtime servers: pure S3 + CloudFront, pennies to run

Wrap-up

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)

References & notes

  • Repo overview, features, env files, and deploy scripts. (GitHub)
  • CloudFront + ACM certificate must be in us-east-1. (AWS Documentation)
  • Route 53 alias records to CloudFront; when to use A/AAAA alias vs CNAME. (AWS Documentation)
  • CloudFront caching, invalidations, and cache-control guidance. (AWS Documentation)