根据参数值创建 AWS 资源

时间:2021-01-06 21:32:58

标签: amazon-web-services conditional-statements amazon-cloudformation

我想根据 CloudFormation 中的条件创建 AWS 资源。条件取决于参数值,因此如果参数值为空,则不创建 AWS 资源。如果我为参数提供值,则应仅创建 AWS 资源。参数值来自如下变量。

我可以在条件部分使用 AWS::NoValue 以便在 S3_NAME 为空时不创建 aws 资源吗?或者不知道我应该如何处理这个。

Conditions:
  CreateS3Alerts:
    Fn::Not
      - ${self:custom.config.S3_NAME}
      - AWS::NoValue

S35xxErrors:
    Type: AWS::CloudWatch::Alarm
    Condition: CreateS3Alerts
    Properties:
      AlarmName: "S3 5XX Errors"

1 个答案:

答案 0 :(得分:0)

不能这样做。从 docs 开始,您只能使用

<块引用>

另一个条件、参数值或映射

带条件的常见模式是使用 Equals,它检查您是否有空字符串

Conditions:
  CreateS3Alerts:
    !Not [!Equals [${self:custom.config.S3_NAME}, ""]]