Skip to content

Github Action that deploys an artifact to an S3 bucket, and invalidates a Cloudfront invalidation. Used to standardize S3 deployment of my web applications.

Notifications You must be signed in to change notification settings

jmuzina/deploy_s3_with_cloudfront_invalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Deploy S3 With Cloudfront Invalidation

Deploys an artifact to Amazon S3, and creates a Cloudfront Invalidation to ensure the latest files are served.

Inputs:

Name Description Type Default
environment Name of the environment you are deploying the artifact to string prod
cloudfront_invalidation Path or pattern within your web artifact for which to create a Cloudfront invalidation string /*

Secrets:

Name Description
AWS_S3_BUCKET_NAME Name of the S3 bucket to upload static web build artifacts to
AWS_ACCESS_KEY_ID AWS IAM Access Key ID for accessing resources
AWS_SECRET_ACCESS_KEY AWS IAM Secret Access Key for accessing resources
AWS_CLOUDFRONT_DISTRIBUTION_ID ID of the Cloudfront Distribution used by this artifact
AWS_REGION AWS deployment region. See AWS Docs for list of valid values.

Artifact name

Note: in your CI step before calling this workflow, you must upload your build artifact using actions/upload-artifact and assign the artifact name using the format ${{ github.event.repository.name }}-${{ environment }}-${{ github.run_number }}, where environment is some string to distinguish runs of the same repository but different environment.

Example:

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    environment: dev
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2

      - name: Install JS dependencies
        run: npm i

      - name: Build artifact
        run: npm run build

      - name: Archive build artifact
        uses: actions/upload-artifact@v4
        with:
          # Artifact name must match naming convention ${{ github.event.repository.name }}-${{ environment }}-${{ github.run_number }}
          name: ${{ github.event.repository.name }}-dev-${{ github.run_number }}
          path: ./dist/your_project_name
  deploy:
    needs: build
    name: Deploy
    uses: 'jmuzina/deploy_s3_with_cloudfront_invalidation/.github/workflows/[email protected]'
    with:
      environment: dev
    secrets:
      # Make sure you store your secrets in repository actions secrets. Do not store them in cleartext for security reasons.
      AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }}
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
      AWS_REGION: ${{ secrets.AWS_REGION }}

About

Github Action that deploys an artifact to an S3 bucket, and invalidates a Cloudfront invalidation. Used to standardize S3 deployment of my web applications.

Topics

Resources

Stars

Watchers

Forks