What
You can push your static HTML files with their related assets to AWS S3 directly from GitHub Actions whenever you push to GitHub.
How
You will need an AWS IAM user with access to S3 and CloudFront (if you are going to use CloudFront), and an S3 bucket to deploy into.
name: Deploy to S3
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: false
- name: Sync S3 bucket
uses: jakejarvis/s3-sync-action@master
with:
args: --delete
env:
AWS_S3_BUCKET: your-bucket-name
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-west-1'
SOURCE_DIR: '.'
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: your-cf-id
PATHS: "/*"
AWS_REGION: "us-east-1"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
If you are not using a CloudFront distribution to serve the S3 bucket, remove the Invalidate CloudFront step.
To point your apex domain at the CloudFront distribution after deploying, see Add an A Record to Apex Domain on Route 53.