Deploy to S3 with GitHub Actions

Rather than using the AWS Cli commands, using the GitHub Sync to S3 Bucket action: https://github.com/marketplace/actions/s3-sync

Repository setup

  1. Create a directory: .github/workflows
  2. Create a file: main.yml

main.yml

name: Upload Website

on:
  push:
    branches:
      - main

jobs:
  deploy:
    environment: michaellittle.io
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: jakejarvis/s3-sync-action@v0.5.1
        with:
          args: --follow-symlinks --delete --exclude '.git*/*' --exclude '.gitignore' --exclude 'README.md'
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: ap-southeast-4
          SOURCE_DIR: '.'

AWS setup

  1. Create an IAM user.
  2. Create access keys.
  3. Grant S3 permissions (determine the minimum required policy for your bucket and actions).

GitHub Secrets

In your GitHub repo settings, add these secrets: