Monday, October 7, 2024

AWS CDK Set CloudFormation Property Escape Hatch

 Problem:

The CDK does not always support all CloudFormation properties. A super simple escape hatch is to use  a addOverride one-liner. There are more robust escape hatches but this is super simple especially for deeply nested properties. Ideally, these are temporary until the CDK exposes properties directly.

Solution:

// The CDK does not currently support dynamic wildcard branch names (and other GitHub version 2 properties) but CloudFormation does.
const cfnPipeline = pipeline.node.defaultChild as codepipeline.CfnPipeline;
cfnPipeline.addOverride('Properties.Stages.0.Actions.0.Configuration.BranchName', `*-${env}-*`);