1 Answer
- Newest
- Most votes
- Most comments
1
For conditional resource creation using CfnCondition
, you will need to add a condition
property to the cfnOptions of the resource.
Check out this sample:
const enableRefresh = new CfnParameter(this, 'EnableRefresh', { type: 'String', allowedValues: ['true', 'false'], default:'true' }) const isRefreshEnabledCond = new CfnCondition(this, "Refresh enabled",{ expression: Fn.conditionEquals(enableRefresh.valueAsString , 'true') }) const rule = new events.Rule(this, 'Rule', { schedule: events.Schedule.rate(Duration.minutes(100)), }); const cfnRule = rule.node.tryFindChild('Resource') as events.CfnRule; cfnRule.cfnOptions.condition = isRefreshEnabledCond
And run cdk synth
to verify the template. Make sure you see the Condition
attached in the resource definition.
Resources: Rule4C995B7F: Type: AWS::Events::Rule Properties: ScheduleExpression: rate(100 minutes) State: ENABLED Metadata: aws:cdk:path: demo-stack9/Rule/Resource Condition: Refreshenabled
answered 6 months ago
Relevant content
- asked 5 days ago
- asked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago