This project contains an AWS Cloud Development Kit (CDK) template that creates a CodeCommit Git repository, and a static website hosted in Amazon S3, fronted by and Amazon CloudFront CDN. Additionally, it creates the necessary AWS CodeBuild and AWS CodePipeline projects so that every change to content in the Git repository is automatically deployed to the static web site. Finally, an AWS Lambda@Edge function is created to preserve clean URLs in the website (while still protecting the S3 bucket from direct access).
Envrionment variables are used to provide a domain name and an Amazon Certificate Manager ARN, as well as an optional Hugo version and SHA256 checksum.
Benefits of this architecture include:
Easy to deploy - Use the AWS CDK CLI to deploy the infrastructure, then check out the repo and start creating content with Hugo.
Fully managed/scalable - All services leveraged are 100% managed and require no manual scaling or scaling policy creation based on traffic volume is required.
Low cost - Your costs may vary over time and if other resources are running in your AWS account.
- Architecture
- Launch the Infrastructure
- Create your Hugo website
- Useful AWS CDK commands
Follow the steps below to go from CDK installation to publishing your first Hugo post.
Follow the latest instructions from the AWS CDK website to install the CLI. You should be able to check the version from the CLI (your version may not match exactly).
$ cdk --version
0.22.0 (build 644ebf5)
Clone this repo to your local machine and switch to that directory.
$ git clone https://github.com/mikeapted/aws-cdk-hugo-s3.git my-hugo-website
Cloning into 'my-hugo-website'...
remote: Enumerating objects: 44, done.
remote: Counting objects: 100% (44/44), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 44 (delta 19), reused 40 (delta 15), pack-reused 0
Unpacking objects: 100% (44/44), done.
$ cd my-hugo-website
npm i
npm run build
Set the domain name your site will use (apex domain, the www. will be added automatically), and ACM ARN for the CloudFront distribution (and the optional Hugo version and SHA256) using either the AWS CDK context or envrionment variables (they are used in that order of preference).
Edit the cdk.json file in the root directory to update the values.
{
"context": {
"domain": "...",
...
}
}
$ export DOMAIN=...
$ export CERTIFICATE=...
$ export HUGO_VERSION=...
$ export HUGO_SHA256=...
$ cdk ls
HugoAwsCdkStack
$ cdk synth
Resources:
CodeCommitRepository...
...
If you have never used the CDK in the AWS account your credentials are configured for you will need to first bootstrap the CDK (creates a staging S3 bucket).
$ cdk bootstrap
Then deploy the stack to your account.
$ cdk deploy
TBD
npm run build
compile typescript to jsnpm run watch
watch for changes and compilecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template