Serverless PR Preview Deploy
Uses CloudFront + Lambda@Edge to route subdomains to a folder inside a bucket.
Setup
Prerequisites
- A domain name
Setup
- Add the domain to Route 53
- Start the creation of a public certification using Certificate Manager in the
US-EAST-1
region. Use the wildcard version as the domain name (*.example.com
) and the full domain as an additional name (example.com
). For domain verification, allow Certificate Manager to set up Route 53. - Update the following files:
serverless.yml
- Line 3: Set the name of the S3 bucket
- Lines 63 & 64: Update the aliases to the regular domain and wildcard domain (ex:
example.com
&*.example.com
) - Line 66: Update the value to the resource name of the certificate created in step 2
handler.js
- Line 3: Update value to the domain name with prefix of
.
(ex:.example.com
) - Line 5: Update the value to the name of the S3 bucket that was set in
serverless.yml:3
- Line 3: Update value to the domain name with prefix of
- Run
serverless deploy
, cross your fingers and grab a beer cause it'll take a while to run. - Update Route 53 to point to the CloudFront distribution
Usage
Using the S3 cli, copy files to a folder in the bucket name you picked in step 3. To view the deployed site, visit https://{site-bucket-name}.{domain}.com
Credits
Adpated from this SO answer with updates for SPA routing and Serverless deploy