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).
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.
- 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
- SES Receipt Rule Set
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
An example can be found at ./domains/sample.yml
.
- Account specific config
sesReceiptRuleSetName
: The name of the active SES Receipt Rule Set in your accountreceivedEmailTopicArn
: 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 hostedsites
: An array of sites (i.e. subdomains) to hostsubdomain
: The subdomain to host on S3
This software is released under the MIT license. See the license file for more details.