1 S3 bucket, 1 CloudFront distribution, 100 sites.
Hosting many static landing pages/websites? Tired of doing the same rigmarole on NGINX/S3/CloudFront when setting a new one? This is for you.
- Launch Stack.
- Put website files on S3.
- Profit.
- AWS account with permissions to deploy resources through CloudFormation.
- A certificate provisioned through ACM in the
us-east-1
region, covering all domains being setup. - An IAM user with programmatic access (to sync files with S3).
- Click "Launch Stack" at the top. Click "Next".
- Change the Stack Name if you want. Fill in parameters:
CertArn
: ARN of certificate from ACM.- Make sure to create it in the
us-east-1
region!
- Make sure to create it in the
ServedDomains
: Domains to serve. Separate multiple domains with commas.example.com != www.example.com
SyncUserArn
: ARN of users with read/write access to S3 bucket. Separate multiple users with commas.
- "Next", "Next", "Create Stack".
- Once stack creation is complete, load in website and error page files on the created S3 bucket.
- AWS console,
aws s3 cp
oraws s3 sync
. - Put files for each domain in its own folder (e.g.
/example.com/index.htm
forexample.com
). - Put 404 error (only error I have right now) page design on
/error/404.htm
.
- AWS console,
- Stack must be launched on
us-east-1
region. Lambda@Edge requirements. - No server-side content, since the files are hosted in S3.
- Client-side JS and an API can provide server-side content.
- The index page of a folder is
index.htm
only.- Documents w/o an extension (e.g.
folder/doc
) won't redirect to the index page (e.g.folder/doc/index.htm
).
- Documents w/o an extension (e.g.
- The same error page design applies to all websites.
- CloudFront wipes request headers when returning a request to origin for the error document.
- If you know how to bypass this wipe, tweet me or open a pull request!
- Stack deletions will not work the first time.
- Lambda won't let you delete functions until their caches have been removed from all CloudFront edges.
- Let it fail, wait at least 1 hour, try deleting again. It'll work after some time.
Pull Requests, Issues, you know the deal.