Actual alarm name is also used as logic Id which prevents tokens from being used #492
-
BackgroundI am using cdk-monitoring-constructs to add a CloudWatch dashboard with alarms into my project, also would like to prefix all the alarms with the CFN stack name so as to easily differentiate them from others. Problem StatementI thought this would be very easy to achieve but it turns out to be quite difficult. In my CDK code, I used
This is because AlarmFactory uses the alarmName as its logical Id when creating the alarm. I probably could write my own The other options I have thought of including CFN parameter, Custom Resource, but they both end up as a Token at synth time as well. Note that the deliverable of my project is CFN template. Therefore dynamic parameters can only be passed in as CFN parameters. Passing in parameter via CDK props or context is not an option. Any suggestion will be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Finally I solved it using const idTokenPrefixRE = /\$\{.+\}/;
this.monitoringFacade = new MonitoringFacade(this, "MonitoringDashboard", {});
...
Aspects.of(this.monitoringFacade).add(
asAspect((c) => {
// Use Object.assign as node.id is a readonly property
Object.assign(c.node, { id: c.node.id.replace(idTokenPrefixRE, "") });
}),
); |
Beta Was this translation helpful? Give feedback.
Finally I solved it using
Aspects
to loop through and remove the token from node id of all chilren: