How non-97/cloudfront-s3-website works
Project Type and Purpose
• This is an “Infrastructure-as-Code” project using AWS CDK in TypeScript.
• It defines a single CloudFormation stack (“WebsiteStack”) that:
• Provisions an S3 bucket for static assets
• Configures a CloudFront distribution with Lambda@Edge and CloudFront Functions (CF2)
• Attaches an ACM TLS certificate and a Route 53 hosted zone
• Applies a Web Application Firewall (WAF)
• Collects and processes access logs
File Structure
• Top-level:
• cdk.json, tsconfig.json, package.json – CDK app config
• bin/website.ts – CDK app entry
• lib/website-stack.ts – Stack definition
• lib/construct/*.ts – Reusable constructs: Bucket, Certificate, ContentDelivery, HostedZone, LogAnalytics, WAF
• lib/src/cf2/* – JavaScript code for CloudFront Functions (directory‐index, rewrite‐to‐webp, normalize keys)
• lib/src/lambda/* – TypeScript code for Lambda@Edge (same features) and a log‐mover function
• parameter/index.ts – Parameter definitions
• test/website.test.ts – Jest unit test
README
• Confirms it’s a blank CDK TypeScript project.
• Provides common CDK commands (build, deploy, synth, test).
Main Components & Their Interactions
a. Users (HTTPS clients)
b. Amazon Route 53 – DNS
c. AWS Certificate Manager (ACM) – TLS certificate
d. Amazon CloudFront Distribution
• Origin: Amazon S3 Static Website Bucket
• Edge Logic:
– CloudFront Functions (CF2) for directory indexing, WebP rewrites, cache-key normalization
– Lambda@Edge versions of the same logic for Lambda runtime support
• WAF WebACL attached
• Access Logging → S3 Logs Bucket
e. AWS Lambda (non-edge) “log mover” – processes/moves CloudFront access logs to analytics storage or pipeline
f. Optional: Log Analytics construct (could be CloudWatch Logs, Athena, etc., per construct implementation)
Architectural Patterns & Design Principles
• Modular CDK constructs—each AWS resource group is abstracted
• Edge-optimized delivery using CloudFront Functions and Lambda@Edge (low latency)
• Infrastructure as Code with a single source of truth
• Separation of static content, dynamic edge logic, and logging pipelines
• Parameterization for reusability across environments