CodePipeline: How to reference nested CloudFormation Stacks from GitHub as Source


Our CloudFormation templates are stored in GitHub. Inside CodePipeline we’re using GitHub as our Source, but we can’t reference nested CloudFormation Stacks when they’re not stored on S3.

How can we reference CloudFormation nested Stacks when using GitHub as our source in CodePipeline?

If this is not possible, how can we upload the CloudFormation Templates from GitHub to S3 between the Source Stage (from GitHub) and the Deploy Stage in CodePipeline?


There are two approaches I can think of to reference nested CloudFormation Stacks from a GitHub source for a CodePipeline deployment:

1. pre-commit Git hook

Add a pre-commit client-side Git hook that runs aws cloudformation package on your template, committing a generated template with the S3 reference to your GitHub repository alongside the changes to the source template.

The benefit to this approach is that you can leverage the existing template-rewriting logic in aws cloudformation package, and you don’t have to modify your existing CodePipeline configuration.

2. Lambda pipeline Stage

Add a Lambda-based pipeline Stage that extracts the specified nested-stack template file from the GitHub Source Artifact and uploads it to a specified location in S3 referenced in the parent stack template.

The benefit to this approach is that the Pipeline will remain entirely self-contained, without any extra pre-processing step required by the committer.

I’ve published a complete reference example implementation to wjordan/aws-codepipeline-nested-stack:

Launch Stack

Leave a Reply