๐ชStatic website deployment preview with S3 and CloudFront
How to create deployment previews with S3 and CloudFront
Architecture
graph TD
A[User accesses preview subdomain<br/>e.g., sprint-0x.preview.domain.app] -->|DNS| B[Route 53 Wildcard Record]
B --> C[CloudFront Distribution<br/>with Wildcard Domain]
C --> D[Lambda@Edge Function<br/>(deployed in us-east-1)]
D -->|Extract subdomain (sprint-0x)| E[Rewrite URI to<br/>sprint-0x/index.html]
D -->|Optional Basic Auth| F{Authorized?}
F -- Yes --> G[Forward request to S3 origin]
F -- No --> H[Return 401 Unauthorized]
G --> I[S3 Bucket<br/>(Static Website Host)]
I --> J[Return deployment preview page]
subgraph Certs
K[ACM Cert - us-east-1<br/>(for CloudFront)]
L[ACM Cert - App Region<br/>(optional)]
end
C --> K
C --> LPrerequisites
The sample source code for the function:
Implement
PreviousCloud Run Deployment Preview Github Actions workflowsNextAllow Docker Remote API access over Tailscale network
Last updated