Overview
The starter kit ships with GitHub Actions workflows generated by Projen so every merge to your default branch produces a deterministic deploy. This guide explains the lifecycle from merge to rollout and how to interact with the pipelines.
Trigger flow
- Push or merge into
main: Projen creates a workflow namedcdk-deploy-<env>for each environment. The first environment inenvironmentConfigs(typicallytest) runs on every push tomain. - Environment chaining: Subsequent environments trigger via
workflow_runwhen the previous deploy finishes successfully. For example,cdk-deploy-productionwaits forcdk-deploy-testto succeed before starting. - Pull requests: Branch deploy workflows named
cdk-deploy-<env>-branchrun whenenableBranchDeployis true for that environment. They deploy stacks with branch suffixes so previews stay isolated. Cleanup is handled bycdk-destroy-<env>-branchon branch deletion or PR close. - CDK diff on pull requests: The
cdk-diff-pr-commentworkflow runs automatically on every pull request targetingmain. It generates a CDK diff comparing your PR branch against the production environment and posts the results as a comment directly in the pull request. This gives reviewers visibility into infrastructure changes before merging. - Manual runs: Every workflow exposes the
workflow_dispatchtrigger, enabling re-runs or ad-hoc deploys straight from the GitHub Actions UI.
What each deploy job does
Inside the deploy job (see createCdkDeploymentWorkflows) GitHub Actions performs:
- Checkout & setup:
actions/checkoutpulls the repo, thenactions/setup-nodeinstalls the Node.js version from.projenrc.ts. - Install dependencies:
npm ciinstalls dependencies exactly as defined inpackage-lock.json. - Assume the OIDC role:
aws-actions/configure-aws-credentials@v4exchanges the GitHub Actions identity for the IAM role created byFoundationStack. - Synth: Runs
npm run <env>:synth, ensuring CloudFormation templates match expectations before deploying. - Deploy: Runs
npm run <env>:deploy:all, deploying the stacks defined insrc/main.tsto the target AWS account and region.
For branch deploy jobs, the same steps run, but Projen injects GIT_BRANCH_REF so stack names include a branch suffix. Destroy workflows call npm run <env>:branch:destroy:all with the proper branch reference.
CDK diff workflow
The cdk-diff-pr-comment workflow provides early visibility into infrastructure changes before they're merged:
- Trigger: Runs on
pull_request_targetwhen opening or updating a PR againstmain. - Security: Uses
pull_request_targetto access repository secrets while checking out the PR branch SHA directly. - Diff generation: Runs
npm run production:diff:allto compare the PR branch against the current production environment. - PR comment: Uses the
towardsthecloud/aws-cdk-diff-pr-commenteraction to post or update a comment with the diff output, including a custom header showing the environment and region. - Permissions: Requires
contents: read,id-token: write(for OIDC authentication), andpull-requests: write(to post comments).
This workflow helps reviewers understand infrastructure changes at a glance without needing to run cdk diff locally.
Monitoring and troubleshooting
- GitHub Actions UI: track the workflow progress directly in
Actions. Logs show the exact Projen task executing so you can reproduce locally. - CloudFormation stack events: The stack names match
createEnvResourceName('StackName'), so failures are easy to locate in the AWS console. - Rerunning: Use
workflow_dispatchor the "Re-run jobs" button after fixing issues. Just ensure the branch you rerun from still matches the intended state.
Before you push
- Run through the Local Development guide to synth/diff locally and keep formatting tidy.
- If you changed
.projenrc.ts, runnpx projenso the generated workflows stay in sync with the new environment layout.
Advanced configuration
- Edit
environmentConfigsin.projenrc.tsto change deployment order, AWS accounts, or to opt environments in/out of branch deploys. - Need additional stages (for example,
staging)? Add them to the array, rerunnpx projen, and newcdk-deploy-<env>workflows will appear automatically. - To adjust step logic or concurrency, modify
createCdkDeploymentWorkflowsand rerun Projen.
Ready to experiment with feature branches? Continue with Branch-based Development.