Blog

Reviewing CloudFormation change sets in GitHub Actions

Stackmuster

A one-line change to a template goes through review and merges. The pipeline runs aws cloudformation deploy. Ten minutes later someone notices the DynamoDB table is new and empty.

The change renamed the table. CloudFormation can’t rename a table in place, so it created a new one and deleted the old one. The log said so, after it had happened.

This guide sets up a pipeline that shows you that kind of change before it runs. It uses CloudFormation change sets and GitHub Actions, and nothing else. You get a readable plan on every pull request and push, an approval step before anything runs in production, and a clear warning when a change will remove or replace resources.

Why deploying straight from CI is risky

aws cloudformation deploy creates a change set and executes it straight away. That’s convenient, and it’s fine for a sandbox. For anything that holds data, it means the first time you see the plan is in the job log, after it has run.

The risky changes are the ones that look small in a diff:

  • Replacements. Changing some properties forces CloudFormation to create a new resource and delete the old one. Renaming a table, changing a database identifier or moving a resource to a different subnet are common examples. The template diff is one line. The effect is a new, empty resource.
  • Removals. Deleting a resource block from a template deletes the resource. So does a bad merge that drops a block by accident.
  • Conditional replacements. Sometimes CloudFormation can’t tell in advance whether a change needs a replacement. It reports these as Conditional. Treat them as replacements until you know otherwise.

DeletionPolicy and UpdateReplacePolicy can keep the old resource when this happens. They’re worth setting on anything stateful. But they’re a safety net, not a review step.

Plan, review, apply

A change set is CloudFormation’s plan. You give it a template and parameters, and it tells you what it would add, modify and remove, and whether each modification needs a replacement. Creating a change set changes nothing. Executing it does.

That splits a deployment into three steps:

  1. Plan. Create a change set and wait for CloudFormation to work out the changes.
  2. Review. Show the changes to a person in a form they can read quickly.
  3. Apply. Run that exact change set, not a fresh deploy that might differ from what was reviewed.

The third point matters. If the apply job ran aws cloudformation deploy again, the reviewer would be approving one plan and getting another. Passing the change set name from the plan job to the apply job makes sure they get what they approved.

What you need first

The examples use one stack called orders-api in eu-west-2, laid out like this:

stacks/
  orders-api.yaml       # the template
params/
  orders-api.json       # parameters, in the CloudFormation CLI JSON format
scripts/
  cfn-plan.sh
  cfn-apply.sh
.github/workflows/
  orders-api.yml

You also need two IAM roles in the target account, both trusting GitHub’s OIDC provider. GitHub puts the context of each job into the token’s sub claim, so each role can trust only the jobs that should use it:

RoleUsed byTrusts subNeeds
Plan roleThe plan job and the clean-up jobrepo:<org>/<repo>:pull_request and repo:<org>/<repo>:ref:refs/heads/mainChange set and read actions only, such as cloudformation:CreateChangeSet, DescribeChangeSet, DeleteChangeSet, ListChangeSets and DescribeStacks
Deploy roleThe apply jobrepo:<org>/<repo>:environment:prodcloudformation:ExecuteChangeSet, DescribeChangeSet, DescribeStacks and DescribeStackEvents, plus permission to create whatever the template creates

Keep the plan role narrow. A pull_request workflow runs the version of the workflow file on the pull request branch. Anyone who can push a branch can change what that job does with the role. A role that can only create and read change sets can’t change your infrastructure.

When a job uses a GitHub environment, the sub claim names the environment, not the branch. That is why the deploy role trusts environment:prod. In the environment’s settings, limit deployment branches to main, so a workflow on another branch can’t use it.

The plan script

The plan script does the work that’s awkward to express in YAML. It’s plain bash and the AWS CLI, so you can run it on your own machine too:

#!/usr/bin/env bash
# cfn-plan.sh
# Creates a CloudFormation change set for one stack, waits for it, and writes
# a readable summary. It never executes anything.
#
# Usage: cfn-plan.sh <stack-name> <template-file> <parameters-file> <change-set-name>
#
# Optional environment variables:
#   DEPLOY_ENV  adds an "environment" tag to the stack, for example prod
#
# Writes to $GITHUB_OUTPUT when it is set:
#   change_set_name  the name passed in
#   has_changes      true or false
#   destructive      true if any resource is removed or may be replaced
# Writes a Markdown summary to $GITHUB_STEP_SUMMARY, or to the terminal.

set -euo pipefail

if [[ $# -ne 4 ]]; then
  echo "usage: $0 <stack-name> <template-file> <parameters-file> <change-set-name>" >&2
  exit 2
fi

STACK="$1"
TEMPLATE="$2"
PARAMS="$3"
CHANGE_SET="$4"
OUTPUT="${GITHUB_OUTPUT:-/dev/null}"
SUMMARY="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
LABEL="$STACK${DEPLOY_ENV:+ ($DEPLOY_ENV, ${AWS_REGION:-default region})}"

fail() {
  echo "::error::$*"
  exit 1
}

# 1. CREATE or UPDATE?
# describe-stacks fails with a ValidationError when the stack doesn't exist.
# A stack in REVIEW_IN_PROGRESS was left by a CREATE change set that never
# ran. It has no resources, so it takes another CREATE change set.
if STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK" \
              --query 'Stacks[0].StackStatus' --output text 2>&1); then
  case "$STATUS" in
    REVIEW_IN_PROGRESS) TYPE=CREATE ;;
    ROLLBACK_COMPLETE)  fail "$STACK is in ROLLBACK_COMPLETE. A failed create can't be updated. Delete the stack, then plan again." ;;
    *)                  TYPE=UPDATE ;;
  esac
elif [[ "$STATUS" == *"does not exist"* ]]; then
  TYPE=CREATE
else
  fail "Could not read $STACK: $STATUS"
fi

# 2. Create the change set.
TAGS=("Key=managed-by,Value=${GITHUB_REPOSITORY:-local}")
if [[ -n "${DEPLOY_ENV:-}" ]]; then
  TAGS+=("Key=environment,Value=$DEPLOY_ENV")
fi

ARGS=(
  --stack-name "$STACK"
  --change-set-name "$CHANGE_SET"
  --change-set-type "$TYPE"
  --template-body "file://$TEMPLATE"
  --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM
  --tags "${TAGS[@]}"
)
if [[ -f "$PARAMS" ]]; then
  ARGS+=(--parameters "file://$PARAMS")
fi

CHANGE_SET_ID=$(aws cloudformation create-change-set "${ARGS[@]}" --query Id --output text)
echo "change_set_name=$CHANGE_SET" >> "$OUTPUT"
echo "Created $TYPE change set $CHANGE_SET for $STACK"

# 3. Wait. The waiter exits non-zero when the change set FAILS, and a change
# set with no changes is marked FAILED, so check why before giving up.
if ! aws cloudformation wait change-set-create-complete --change-set-name "$CHANGE_SET_ID"; then
  IFS=$'\t' read -r CS_STATUS REASON < <(aws cloudformation describe-change-set \
    --change-set-name "$CHANGE_SET_ID" --query '[Status, StatusReason]' --output text)

  if [[ "$CS_STATUS" == FAILED &&
        ( "$REASON" == *"didn't contain changes"* || "$REASON" == *"No updates are to be performed"* ) ]]; then
    aws cloudformation delete-change-set --change-set-name "$CHANGE_SET_ID"
    echo "has_changes=false" >> "$OUTPUT"
    echo "destructive=false" >> "$OUTPUT"
    printf '### %s\n\nNo changes. Nothing to deploy.\n' "$LABEL" >> "$SUMMARY"
    exit 0
  fi
  fail "Change set $CHANGE_SET failed: $REASON"
fi

# 4. Summarise. Replacement is only set for Modify actions.
ROWS=$(aws cloudformation describe-change-set --change-set-name "$CHANGE_SET_ID" \
  --query "Changes[].ResourceChange.[Action, LogicalResourceId, ResourceType, Replacement || '-']" \
  --output text)

DESTRUCTIVE=false
TABLE=""
while IFS=$'\t' read -r ACTION LOGICAL_ID RESOURCE_TYPE REPLACEMENT; do
  [[ -z "$ACTION" ]] && continue
  MARK=""
  if [[ "$ACTION" == Remove || "$REPLACEMENT" == True || "$REPLACEMENT" == Conditional ]]; then
    MARK=" **(destructive)**"
    DESTRUCTIVE=true
  fi
  TABLE+="| ${ACTION}${MARK} | ${LOGICAL_ID} | ${RESOURCE_TYPE} | ${REPLACEMENT} |"$'\n'
done <<< "$ROWS"

{
  printf '### %s\n\n' "$LABEL"
  printf 'Change set: %s (%s)\n\n' "$CHANGE_SET" "$TYPE"
  if [[ "$DESTRUCTIVE" == true ]]; then
    printf '> **This change set removes or replaces resources.** Check for data before approving.\n\n'
  fi
  printf '| Action | Logical ID | Type | Replacement |\n'
  printf '| --- | --- | --- | --- |\n'
  printf '%s\n' "$TABLE"
} >> "$SUMMARY"

echo "has_changes=true" >> "$OUTPUT"
echo "destructive=$DESTRUCTIVE" >> "$OUTPUT"

Three parts need explaining.

CREATE or UPDATE. create-change-set needs to know whether the stack exists. The script asks describe-stacks, which fails with a ValidationError for a missing stack. A stack in REVIEW_IN_PROGRESS exists but has never been created. That’s what a CREATE change set leaves behind when nobody executes it. It has no resources, so it takes another CREATE change set.

No changes is not an error. A change set with nothing in it ends up FAILED, so the script checks why the waiter failed before failing the job. When the change set has no changes covers this below.

Destructive changes. In describe-change-set, each change has an Action (Add, Modify, Remove, Import or Dynamic) and, for modifications, a Replacement (True, False or Conditional). The script flags anything with Action set to Remove, or Replacement set to True or Conditional.

The apply script

The apply script runs one named change set and waits for the result:

#!/usr/bin/env bash
# cfn-apply.sh
# Executes one named change set and waits for the stack to finish.
#
# Usage: cfn-apply.sh <stack-name> <change-set-name>

set -euo pipefail

if [[ $# -ne 2 ]]; then
  echo "usage: $0 <stack-name> <change-set-name>" >&2
  exit 2
fi

STACK="$1"
CHANGE_SET="$2"

if ! [[ "$CHANGE_SET" =~ ^[A-Za-z][-A-Za-z0-9]*$ ]]; then
  echo "::error::That is not a valid change set name."
  exit 1
fi

# The change set must still exist and be ready to run. Executing any change
# set deletes the others on the same stack, so an older plan can't be applied
# on top of a newer deployment.
if ! STATE=$(aws cloudformation describe-change-set --stack-name "$STACK" \
               --change-set-name "$CHANGE_SET" \
               --query '[ExecutionStatus, Status]' --output text 2>&1); then
  echo "::error::Change set $CHANGE_SET was not found on $STACK. It may have been run, deleted or replaced by a newer plan. Run the plan again."
  exit 1
fi
read -r EXEC_STATUS CS_STATUS <<< "$STATE"
if [[ "$EXEC_STATUS" != AVAILABLE ]]; then
  echo "::error::Change set $CHANGE_SET can't be run: ExecutionStatus=$EXEC_STATUS, Status=$CS_STATUS."
  exit 1
fi

# A stack in REVIEW_IN_PROGRESS is being created; anything else is an update.
STACK_STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK" \
  --query 'Stacks[0].StackStatus' --output text)
if [[ "$STACK_STATUS" == REVIEW_IN_PROGRESS ]]; then
  WAITER=stack-create-complete
else
  WAITER=stack-update-complete
fi

aws cloudformation execute-change-set --stack-name "$STACK" --change-set-name "$CHANGE_SET"
echo "Running $CHANGE_SET on $STACK, waiting for ${WAITER#stack-}"

if ! aws cloudformation wait "$WAITER" --stack-name "$STACK"; then
  echo "::error::$STACK did not reach ${WAITER#stack-}. Recent failures:"
  aws cloudformation describe-stack-events --stack-name "$STACK" --max-items 50 \
    --query "StackEvents[?contains(ResourceStatus, 'FAILED')].[Timestamp, LogicalResourceId, ResourceStatus, ResourceStatusReason]" \
    --output table
  exit 1
fi

echo "$STACK is ${WAITER#stack-}"

It checks the change set is still AVAILABLE before running it. When CloudFormation executes a change set, it deletes the other change sets on that stack. So if a newer plan has already been applied, an older approval fails with a clear message instead of rolling the stack backwards.

The stack-create-complete and stack-update-complete waiters poll every 30 seconds for up to an hour. If the stack fails and rolls back, the script prints the failed events so the reason is in the job log.

The workflow

name: orders-api

on:
  pull_request:
    branches: [main]
    paths:
      - "stacks/orders-api.yaml"
      - "params/orders-api.json"
      - "scripts/cfn-*.sh"
      - ".github/workflows/orders-api.yml"
  push:
    branches: [main]
    paths:
      - "stacks/orders-api.yaml"
      - "params/orders-api.json"
      - "scripts/cfn-*.sh"
      - ".github/workflows/orders-api.yml"

permissions:
  contents: read
  id-token: write # lets each job request a GitHub OIDC token

env:
  AWS_REGION: eu-west-2
  STACK_NAME: orders-api
  TEMPLATE: stacks/orders-api.yaml
  PARAMETERS: params/orders-api.json
  DEPLOY_ENV: prod
  PLAN_ROLE_ARN: arn:aws:iam::123456789012:role/<plan-role-name>
  DEPLOY_ROLE_ARN: arn:aws:iam::123456789012:role/<deploy-role-name>

defaults:
  run:
    shell: bash

jobs:
  plan:
    runs-on: ubuntu-latest
    outputs:
      change_set_name: ${{ steps.plan.outputs.change_set_name }}
      has_changes: ${{ steps.plan.outputs.has_changes }}
      destructive: ${{ steps.plan.outputs.destructive }}
    steps:
      - uses: actions/checkout@v7

      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: ${{ env.PLAN_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

      - name: Create change set
        id: plan
        env:
          CHANGE_SET: gh-${{ github.run_id }}-${{ github.run_attempt }}
        run: bash scripts/cfn-plan.sh "$STACK_NAME" "$TEMPLATE" "$PARAMETERS" "$CHANGE_SET"

      # A pull request only previews. Its change set is never run, so delete it.
      - name: Discard preview change set
        if: github.event_name == 'pull_request' && steps.plan.outputs.has_changes == 'true'
        env:
          CHANGE_SET: ${{ steps.plan.outputs.change_set_name }}
        run: aws cloudformation delete-change-set --stack-name "$STACK_NAME" --change-set-name "$CHANGE_SET"

  apply:
    needs: plan
    if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.plan.outputs.has_changes == 'true'
    runs-on: ubuntu-latest
    environment: prod # add required reviewers to this environment
    concurrency:
      group: apply-orders-api
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v7

      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: ${{ env.DEPLOY_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

      - name: Execute change set
        env:
          CHANGE_SET: ${{ needs.plan.outputs.change_set_name }}
        run: bash scripts/cfn-apply.sh "$STACK_NAME" "$CHANGE_SET"

How it behaves:

  • On a pull request, the plan job creates a change set, writes the summary and deletes the change set again. Nothing is applied. If the stack is new, the preview leaves an empty stack in REVIEW_IN_PROGRESS. It holds no resources, and the real plan on main reuses it.
  • On a push to main, the plan job creates a change set and keeps it. If there are changes, the apply job waits for approval on the prod environment, then runs that change set.
  • The change set name includes the run ID and attempt, for example gh-1234567890-1. The apply job reads it from the plan job’s outputs, so it always runs the change set that was reviewed.
  • concurrency stops two apply jobs running on the same stack at once.

Pull requests from forks don’t get an OIDC token, so the plan job can’t run for them. That’s usually what you want for a deployment pipeline.

Your template must be under 51,200 bytes to pass with --template-body. For larger templates, upload to S3 first and use --template-url instead. If the template uses transforms, such as AWS::Serverless, add CAPABILITY_AUTO_EXPAND to the capabilities.

Reading the plan

The plan job writes a table to the job summary, which appears on the workflow run’s summary page. Reviewers see it before they approve:

### orders-api (prod, eu-west-2)

Change set: gh-1234567890-1 (UPDATE)

> **This change set removes or replaces resources.** Check for data before approving.

| Action | Logical ID | Type | Replacement |
| --- | --- | --- | --- |
| Modify **(destructive)** | OrdersTable | AWS::DynamoDB::Table | True |
| Modify | OrdersFunction | AWS::Lambda::Function | False |
| Add | OrdersDlq | AWS::SQS::Queue | - |

Rendered, that’s a table with a warning above it. The rule for reviewers is simple. Anything marked destructive needs a reason in the pull request, and a check that the data is safe.

When the change set has no changes

If the template and parameters match what’s already deployed, CloudFormation still creates the change set, then sets its status to FAILED with this reason:

The submitted information didn’t contain changes. Submit different information to create a change set.

Nothing is wrong; there’s just nothing to deploy. But the change-set-create-complete waiter exits with code 255 on a failed change set, so a script that trusts the waiter fails every run where nothing changed.

The plan script handles this in step 3. When the waiter fails, it reads the status reason with describe-change-set. If the change set failed only because it was empty, the script deletes it, sets has_changes=false, notes it in the job summary and exits successfully. The apply job doesn’t run. Any other failure still fails the job.

If you deploy with aws cloudformation deploy instead, the default depends on the CLI version: AWS CLI v2 exits 0 on an empty change set unless you pass --fail-on-empty-changeset, while v1 exits non-zero unless you pass --no-fail-on-empty-changeset. Pass the flag explicitly so the behaviour doesn’t depend on the CLI version. Calling UpdateStack directly returns the error “No updates are to be performed.” instead.

Cleaning up change sets that never ran

Change sets that are never executed stay on the stack. That happens when an approval is rejected, when a run is cancelled, or when a plan fails part-way. They cost nothing, but they clutter the console and confuse people later.

A weekly job can remove ones older than a week:

name: orders-api clean-up

on:
  schedule:
    - cron: "0 3 * * 1" # Mondays, 03:00 UTC
  workflow_dispatch:

permissions:
  contents: read
  id-token: write

env:
  AWS_REGION: eu-west-2
  STACK_NAME: orders-api
  PLAN_ROLE_ARN: arn:aws:iam::123456789012:role/<plan-role-name>
  MAX_AGE_DAYS: "7"

defaults:
  run:
    shell: bash

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: ${{ env.PLAN_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

      - name: Delete old change sets
        run: |
          if ! STATUS=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" \
                          --query 'Stacks[0].StackStatus' --output text 2>/dev/null); then
            echo "$STACK_NAME doesn't exist. Nothing to clean up."
            exit 0
          fi

          CUTOFF=$(date -u -d "${MAX_AGE_DAYS} days ago" +%Y-%m-%dT%H:%M:%S)
          aws cloudformation list-change-sets --stack-name "$STACK_NAME" \
            --query "Summaries[?starts_with(ChangeSetName, 'gh-')].[ChangeSetId, CreationTime]" \
            --output text |
          while IFS=$'\t' read -r ID CREATED; do
            if [[ -n "$ID" && "$CREATED" < "$CUTOFF" ]]; then
              echo "Deleting change set created $CREATED: $ID"
              aws cloudformation delete-change-set --change-set-name "$ID"
            fi
          done

          if [[ "$STATUS" == REVIEW_IN_PROGRESS ]]; then
            echo "::warning::$STACK_NAME is in REVIEW_IN_PROGRESS: it was planned but never created. Delete it if it's no longer wanted."
          fi

It only deletes change sets whose names start with gh-, so it leaves alone anything a person created by hand. It warns about a stack stuck in REVIEW_IN_PROGRESS, rather than deleting it, because only a person knows whether that stack is still wanted. If it isn’t, delete it with aws cloudformation delete-stack --stack-name orders-api. It has no resources to remove.

Stacks left in REVIEW_IN_PROGRESS are one of the common sources of clutter in an account. Finding forgotten CloudFormation stacks has a script that lists them across every region.

Required reviewers and private repositories

This is the part that catches people out. For private repositories, required reviewers on GitHub environments are only available on GitHub Enterprise. On the Free, Pro and Team plans, required reviewers work only in public repositories. On those plans, environment: prod in a private repository won’t pause for anyone.

Environments themselves, and deployment branch rules, are available for private repositories on Pro and Team. Only the reviewers are missing. You have two ways to get an approval step back.

Option 1: approve by running a separate workflow. Remove the apply job from orders-api.yml. The plan job still runs on every push to main and leaves its change set in place, with its name in the job summary. An approver reads the summary, then starts this workflow by hand with that name:

name: orders-api apply

on:
  workflow_dispatch:
    inputs:
      change_set_name:
        description: "Change set name from the plan job summary, for example gh-1234567890-1"
        required: true
        type: string

permissions:
  contents: read
  id-token: write

env:
  AWS_REGION: eu-west-2
  STACK_NAME: orders-api
  DEPLOY_ROLE_ARN: arn:aws:iam::123456789012:role/<deploy-role-name>
  APPROVERS: "<github-username> <github-username>"

defaults:
  run:
    shell: bash

jobs:
  apply:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: prod # no reviewers here, but deployment limited to main
    concurrency:
      group: apply-orders-api
      cancel-in-progress: false
    steps:
      - name: Check the approver
        run: |
          for LOGIN in $APPROVERS; do
            if [[ "$LOGIN" == "$GITHUB_TRIGGERING_ACTOR" ]]; then
              exit 0
            fi
          done
          echo "::error::$GITHUB_TRIGGERING_ACTOR is not on the approver list"
          exit 1

      - uses: actions/checkout@v7

      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: ${{ env.DEPLOY_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

      - name: Execute change set
        env:
          CHANGE_SET: ${{ inputs.change_set_name }}
        run: bash scripts/cfn-apply.sh "$STACK_NAME" "$CHANGE_SET"

Anyone with write access can start a workflow_dispatch workflow, so the first step checks the person who started the run against a list. The job only runs from main, and the prod environment is limited to main, so nobody can dispatch an edited copy from another branch. It’s a weaker control than required reviewers. GitHub won’t stop someone approving their own change. But it does make every production change a deliberate act by a named person, with the plan in front of them.

The job still uses the prod environment, with no reviewers, so its OIDC sub claim stays repo:<org>/<repo>:environment:prod. The deploy role’s trust policy doesn’t change, and the plan job, which has no environment, still can’t assume it. On GitHub Free, where private repositories don’t have environments, you’d have to trust ref:refs/heads/main instead. The plan job on main gets that same claim, so give it a separate role and accept that the two are told apart only by what’s in the workflow files.

Option 2: approve the merge, not the deployment. Use branch protection or a ruleset on main to require an approving review before merging, and auto-apply on push. Reviewers approve the plan that the pull request’s plan job wrote. This needs a paid plan (Pro, Team or Enterprise) for private repositories. Its weakness is timing: the plan was made when the pull request was opened, and the account may have changed since. The apply-time check in cfn-apply.sh still runs the change set made on main, but nobody looks at that one before it runs.

Optional: only ask for approval when something is destructive

Approving every change gets tedious, and tedious approvals stop being read. One way round it is to auto-apply additions and in-place updates, and only stop for removals and replacements.

The plan job already outputs destructive. Change the apply job to pick its environment from it:

apply:
  needs: plan
  if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.plan.outputs.has_changes == 'true'
  runs-on: ubuntu-latest
  # prod has required reviewers. prod-auto has none, and is limited to main.
  environment: ${{ needs.plan.outputs.destructive == 'true' && 'prod' || 'prod-auto' }}
  concurrency:
    group: apply-orders-api
    cancel-in-progress: false
  steps:
    - uses: actions/checkout@v7
    - uses: aws-actions/configure-aws-credentials@v6
      with:
        role-to-assume: ${{ env.DEPLOY_ROLE_ARN }}
        aws-region: ${{ env.AWS_REGION }}
    - name: Execute change set
      env:
        CHANGE_SET: ${{ needs.plan.outputs.change_set_name }}
      run: bash scripts/cfn-apply.sh "$STACK_NAME" "$CHANGE_SET"

Create a second environment, prod-auto, with no reviewers and deployment limited to main. Then add repo:<org>/<repo>:environment:prod-auto to the deploy role’s trust policy alongside environment:prod.

Be honest about what this skips. An in-place modify can still cause an outage. A bad security group rule or a broken Lambda function both apply without replacement. This setup puts reviewers’ attention on the changes that lose data. It doesn’t replace code review.

Limits of this approach

This works well for a handful of stacks. A few things get harder as you grow.

One workflow per stack. Each stack needs its own workflow, or at least its own job. You can turn the plan and apply jobs into a reusable workflow and call it once per stack. You still have to add a call for every new template.

Ordering between stacks. If one stack exports a value another imports, the exporting stack has to deploy first. Within one workflow you can express that with needs. Across workflows, GitHub has no ordering, so you’re relying on timing.

Deleting a template doesn’t delete its stack. The workflow’s paths filter doesn’t fire for a template that’s gone. Even if it did, a change set can’t describe “this stack should no longer exist”. The stack keeps running. Deleting CloudFormation stacks when the template is removed from Git covers how to handle that safely.

Changes made outside CloudFormation. A change set compares your template with the template the stack was last deployed with. If someone changed a resource by hand, the plan may not show it.

Nested stacks. By default, a change to a nested stack appears as one Modify of an AWS::CloudFormation::Stack resource. Add --include-nested-stacks to create-change-set to see what changes inside it.

If you’d rather not maintain this yourself

The workflows above are a solid base, and plenty of teams run something like them for years. The cost is that every new stack needs wiring up, and deletions still need their own process.

Stackmuster is built to plan every stack on push, hold destructive changes for approval, and delete a stack once its template is removed and the deletion is approved. It’s the same plan, review and apply cycle, without a workflow to wire up for each stack.

If you’re comparing it with AWS’s built-in option, see how Stackmuster compares with CloudFormation Git sync. If you’re moving off AWS Proton, the Proton migration guide covers what happens to your stacks.

Sources

Early access, from November 2026

Stackmuster is not available yet. One email when it opens.

One email when early access opens, around November 2026. Nothing else, and no sharing with anyone.