$ scaffold aws:static-website
This infrastructure uses the static website hosting capabilities of AWS S3 to host your static website in a serverless way.
Your GitHub account will be connected to CodePipeline and CodeBuild, so you will be able to build, test and deploy your favorite SPA and SSG frameworks (React JS, Vue JS, Gatsby JS, Hugo...) using the usual git push command.
To use an ACM certificate with Amazon CloudFront, the certificate must be requested in the US East (N. Virginia) region.
This infrastructure also uses SSM Parameters Store to store your build environment variables.
|The command that needs to be run to build your website (e.g. npm i && npm run build) (optional).
|The directory where the build command output your website (e.g. build/) (optional).
|The domain name(s) that you want to use for your website.
|We need to wait for the ACM certificate to be "issued" to enable HTTPS. See the "after install" section to learn more.
|The branch from which you want to deploy.
|The GitHub OAuth token that will be used by CodePipeline to pull your source code from your repository.
|The GitHub repository that contains your source code.
|The owner of your GitHub repository. Can be a regular user or an organization.
|A random token that will be used by CodePipeline and GitHub to prevent impersonation.
|The AWS named profile used to create your infrastructure.
|The AWS region where you want to create your infrastructure.
|The AWS S3 bucket that will contain the Terraform state of your infrastructure.
|The AWS DynamoDB table that will be used to store the Terraform state locks.
|The S3 bucket key under which your Terraform state will be saved.
|An unique custom prefix used to avoid name colision with existing resources.
S3 will be used to store your website source code.
CloudFront will be used to serve your website from your S3 bucket.
CodePipeline will be used to manage the deployments of your website
CodeBuild will be used to run the builds of your website.
ACM will be used to manage the SSL certificate of your website.
SSM Parameter Store will be used to store the environment variables of your builds.
This infrastructure exports three Terraform outputs: cloudfront_distribution_uri, pipeline_execution_details_url and ssl_validation_dns_records.
The cloudfront_distribution_uri output value contains the URI of your CloudFront distribution. You could use it to access your website while your DNS are propagating.
The pipeline_execution_details_url output value contains the URL of your pipeline execution details.
The ssl_validation_dns_records output value contains the DNS records that you need to set in order to validate your ACM certificate (see below).
The way you will set up your domain name will vary according to the presence or absence of a subdomain.
If your domain name doesn't have any subdomains, you will need to add two DNS records:
If your domain name has a subdomain, you will need to add one CNAME record:
The ssl_validation_dns_records output value contains the DNS records that you need to set in order to validate your ACM certificate.
Once set, you will need to wait for the status of your certificate to switch from "pending" to "issued" to use it with your application load balancer.
You could then set the ENABLE_HTTPS environment variable to "true" in your local env file and run the scaffold apply command to update your infrastructure.
CodeBuild uses a YAML file to describe all the steps that a stage requires. This file is located in the templates directory at the root of your infrastructure:
You could update this file directly to customize your pipeline build stage.
To add an environment variable to the build stage all you have to do is to add an environment variable that starts with BUILD_ to your infrastructure code.
For example, let's say that you want to add a TOKEN variable to your build. You will first add it to your .env file:
Then, given that this value is secret you choose to define it in your local env file:
One done, you could access your environment variables in your buildspec file:
- echo $TOKEN
Remember to run the scaffold apply command each time you update your infrastructure code.