Reputation: 5142
When creating a subscription in CDK, how can I make the subscription only if the particular condition is met? Eg. in cloud formation, it would be something like:
QueueSubscription:
Type: AWS::SNS::Subscription
Condition: IsNotDev
Properties:
Protocol: sqs
TopicArn:
topic-arn
Endpoint:
Fn::GetAtt:
- Queue
- Arn
In cdk, I know how to Create the subscription as follows:
new CfnSubscription(construct, “QueueSubscription”, CfnSubscriptionProps.builder()
.topicArn(“arn of topic”)
.region(sourceRegion)
.protocol(“sqs”)
.endpoint(queue.getArn())
.build());
But how do I add the condition in here?
Upvotes: 0
Views: 747
Reputation: 175
Use regular if
statement, i.e. create the resource conditionally:
const isDev = /* your condition */
if (!isDev) {
new CfnSubscription(construct, “QueueSubscription”,
CfnSubscriptionProps.builder()
.topicArn(“arn of topic”)
.region(sourceRegion)
.protocol(“sqs”)
.endpoint(queue.getArn())
.build());
}
Upvotes: 0