Set up CloudFront deploy workflow
This guide shows how to set up automated deployment of static sites to S3 and CloudFront using GitHub Actions.
Reference implementation
See how CloudFront deploy workflow is configured in golden-path-docs
.
Things to consider
This workflow relies on the IAM role created by the CloudFront static website template with IamForCicd.Enable
set to true
.
The workflow uses Docker to build your static site and requires a Dockerfile that produces built files in a specific location within the container.
Before you begin
- You have set up a CloudFront static website using the CloudFront static website template
- You have enabled
IamForCicd
and run theset_github_secrets.sh
script to configure GitHub secrets - Your application repository has a Dockerfile that builds your static site
Step 1: Create GitHub Actions configuration
Navigate to your application repository
Create the GitHub Actions configuration directories
Create a common configuration file
AccountId: "1234567890"
Region: "eu-west-1"
Team: "pirates"
Environment: "pirates-dev"
Create a packages.yml file
DefaultPackagePathPrefix: "boilerplate/github-actions"
Step 2: Add the package
Add the CloudFront deploy package
Create package configuration:
Name: "monkey"
Environment: "pirates-dev"
DockerContext: "."
DockerfilePath: "Dockerfile"
ContainerSitePath: "/static-website" # (1)!
- Path inside the Docker container where the built static files are located.
Example Dockerfile
where ContainerSitePath
is /static-website
FROM busybox AS build
RUN mkdir -p /static-website && echo "Hello world!" > /static-website/index.html
Warning
The stage must be named build
.
Install the package to generate the workflow file:
Step 3: Verify
Check that the workflow file was created
You should see a file named _gp_monkey_pirates-dev_cloudfront_deploy.yml
.
Check that the secrets exist:
You should see these secrets:
AWS_ROLE_ARN
S3_BUCKET_NAME
CLOUDFRONT_DISTRIBUTION_ID
Push your changes to trigger the workflow
The workflow will:
- Build your static site using Docker
- Extract the built files from the container
- Sync files to your S3 bucket
- Create CloudFront cache invalidations
Next step
Your static site will now be automatically deployed when you push changes to your repository. Monitor the Actions tab in GitHub to see the deployment progress.