AWS CloudFormation GitHub Action

Posted on: Saturday, 11 December 2021

I've been looking around for a good existing GitHub Action to deploy my CloudFormation stack but the official CloudFormation Action is archived with no explanation why, so I decided to build my own and added some new features.

Introducing AWS CloudFormation GitHub Action: A GitHub Action to create/update your CloudFormation stack.

The Action will comment on Pull Requests with ChangeSet and Output details.

Example actions yaml:

name: 'deploy'

concurrency:
  group: prod_deploy
  cancel-in-progress: false

on:
  repository_dispatch:
  pull_request:
  push:
    branches:
      - main
      - 'releases/*'

jobs:
  deploy-stack:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-east-1

      - name: Update CloudFormation Stack
        id: update-stack
        uses: badsyntax/github-action-aws-cloudformation@v0.0.1
        if:
        with:
          # No need to create this token. Use the default token.
          githubToken: ${{ secrets.GITHUB_TOKEN }}
          stackName: 'example-cloudformation-stack'
          template: './cloudformation/s3bucket-example.yml'
          # Only apply the changeset on pushes to main/release
          applyChangeSet: ${{ github.event_name != 'pull_request' && github.event_name != 'repository_dispatch' }}
          awsRegion: 'us-east-1'
          parameters: 'S3BucketName=example-bucket-us-east-1&S3AllowedOrigins=https://example.com'

      - name: Deploy Website
        run: |
          # Now that the stack is created we can deploy our
          # website to the S3 bucket.
          echo "Deploy to S3 Bucket: $S3BucketName"
        env:
          # Use outputs from the CloudFormation Stack
          S3BucketName: ${{ steps.update-stack.outputs.S3BucketName }}

Note you can "pipe" the CloudFormation outputs into the next step/action.

This is the first step in my plan to create a composite action to create and deploy a static website on the AWS edge. It's gonna be awesome, but I've still got a bit of work to do. The next steps are to create the S3 & CloudFront Actions, then combine all 3 actions into one awesome composite action. I'll post about it when it's ready!

ScreenShots

Applying the ChangeSet:

Apply ChangeSet

Viewing a ChangeSet:

Apply ChangeSet

No changes:

Apply ChangeSet

Comments

(No comments)

Add a new comment