Skip to content

An AWS CDK app for hosting static sites using S3 and CloudFront

License

Notifications You must be signed in to change notification settings

onebytegone/static-site-hosting

Repository files navigation

Static Site Hosting (using AWS)

License Build Status Coverage Status Dependency Status Dev Dependency Status Conventional Commits

What?

This is a serverless static site hosting service build using Amazon S3, CloudFront, and Route 53. It is deployed using the AWS Cloud Development Kit (AWS CDK).

Why?

While it is possible to create the resources manually in the AWS Console, doing so is time consuming and error prone. By having this hosting infrastructure as code, the resource creation is automated and can easily be moved in a new AWS account or duplicated for a new static site.

Setup

Prerequisites

  • Install the AWS CDK (docs)
  • Setup "shared" account resources
    • SES Receipt Rule Set
      • This app will add a rule to this rule set that forwards all received emails, on the given domain, to a provided SNS topic. This is important to have as this app is having ACM use email to validate the domain certificate (An unscientific opinion says it's faster and a little easier than using DNS)
      • Since an account can only have one active receipt rule set, it isn't really practical for this CDK app to create the receipt rule set. As such, it is up to you to create this and add its name to your site config.
      • The name of this rule set is provided in the config as sesReceiptRuleSetName
    • SNS topic
      • This will be the topic that the SES rule will forward any emails sent to the domain to. If desired, you can subscribe an external email to this topic (tutorial).
      • The ARN of the topic is provided in the config as receivedEmailTopicArn

Deployment

git clone [email protected]:onebytegone/static-site-hosting.git
cd static-site-hosting
npm install
cp domains/sample.yml domains/examplecom.yml
vi domains/examplecom.yml # See README.md#Site-Configuration
cdk deploy -c configPath=domains/examplecom.yml 'domain-resources-*'
# Configure your domain to use the Route 53 nameservers
cdk deploy -c configPath=domains/examplecom.yml 'site-hosting-*'
# NOTE: The deploy will hang partway until you approve the certificate created by ACM

Site Configuration

An example can be found at ./domains/sample.yml.

  • Account specific config
    • sesReceiptRuleSetName: The name of the active SES Receipt Rule Set in your account
    • receivedEmailTopicArn: The ARN of the SNS topic you want email sent to the domain to be forwarded to.
  • Site specific config
    • domain: The root domain of the static site to be hosted
    • sites: An array of sites (i.e. subdomains) to host
      • subdomain: The subdomain to host on S3

License

This software is released under the MIT license. See the license file for more details.

About

An AWS CDK app for hosting static sites using S3 and CloudFront

Resources

License

Stars

Watchers

Forks

Packages

No packages published