【问题标题】:Create condition while creating a subscription in CDK在 CDK 中创建订阅时创建条件
【发布时间】:2020-01-21 01:14:17
【问题描述】:

在 CDK 中创建订阅时,如何仅在满足特定条件的情况下进行订阅?例如。在云的形成中,它会是这样的:

QueueSubscription:
    Type: AWS::SNS::Subscription
    Condition: IsNotDev
    Properties:
      Protocol: sqs
      TopicArn:
        topic-arn
      Endpoint:
        Fn::GetAtt:
          - Queue
          - Arn

在 cdk 中,我知道如何创建订阅,如下所示:

 new CfnSubscription(construct, “QueueSubscription”, CfnSubscriptionProps.builder()
        .topicArn(“arn of topic”)
        .region(sourceRegion)
        .protocol(“sqs”)
        .endpoint(queue.getArn())
        .build());

但是如何在这里添加条件呢?

【问题讨论】:

    标签: amazon-cloudformation aws-cdk


    【解决方案1】:

    使用常规的if 语句,即有条件地创建资源:

    const isDev = /* your condition */
    if (!isDev) {
        new CfnSubscription(construct, “QueueSubscription”, 
            CfnSubscriptionProps.builder()
                .topicArn(“arn of topic”)
                .region(sourceRegion)
                .protocol(“sqs”)
                .endpoint(queue.getArn())
                .build());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 2018-10-07
      • 2019-07-07
      • 2021-12-03
      • 1970-01-01
      相关资源
      最近更新 更多