Amazon cloudformation 如何在AWS CloudFormation模板中定义和测试空字符串?
我有一个接受此参数的CloudFormation模板Amazon cloudformation 如何在AWS CloudFormation模板中定义和测试空字符串?,amazon-cloudformation,Amazon Cloudformation,我有一个接受此参数的CloudFormation模板 TargetGroupName: Type: String Description: 'Parameter to override target group name' Default: '' 但是,如何将is定义为空字符串,而不是默认值为空字符串,如下所示?我知道Null不是一个有效的关键字,但我想说明我想做什么 TargetGroupName: Type: String Description: 'Parameter
TargetGroupName:
Type: String
Description: 'Parameter to override target group name'
Default: ''
但是,如何将is定义为空字符串,而不是默认值为空字符串,如下所示?我知道Null不是一个有效的关键字,但我想说明我想做什么
TargetGroupName:
Type: String
Description: 'Parameter to override target group name'
Default: Null
然后,我如何设置一个条件来测试空字符串,就像这样
Conditions:
CreateTargetGroup:
!Not [ !Equals [ !Ref TargetGroupName, Null ] ]
当然,关键字Null会引发CloudFormation脚本验证异常,因为它不是有效的关键字。您可以这样做:
Parameters:
TargetGroupName:
Description: 'Parameter to override target group name'
Type: String
Default: ""
Condition:
IsTargetGroupNameEmpty: !Equals [!Ref "TargetGroupName", ""]
然后在每个您不想创建的资源中,只需通过以下行:
!If [ IsTargetGroupNameEmpty, [ !Ref <RESOURCE_NAME> ], !Ref "AWS::NoValue" ]
请查看以下文档:
您可以这样做:
Parameters:
TargetGroupName:
Description: 'Parameter to override target group name'
Type: String
Default: ""
Condition:
IsTargetGroupNameEmpty: !Equals [!Ref "TargetGroupName", ""]
然后在每个您不想创建的资源中,只需通过以下行:
!If [ IsTargetGroupNameEmpty, [ !Ref <RESOURCE_NAME> ], !Ref "AWS::NoValue" ]
请查看以下文档:
您在哪里发现Null是有效的关键字?它不是。我更新了我的OP来澄清我的问题。我不明白。没有空字符串。它只是一个空字符串。您使用空字符串。除此之外没有别的了。瞧,我不能做我想做的事情,因为CloudFormation没有空字符串。有一个等价物吗?但是,你认为CuldFube中的空字符串是什么?这和上下文中的空字符串有什么不同?在哪里发现Null是有效的关键字?不是。我更新了我的OP来澄清我的问题。我不明白。没有空字符串。它只是一个空字符串。您使用空字符串。除此之外没有别的了。瞧,我不能做我想做的事情,因为CloudFormation没有空字符串。有一个等价物吗?但是,你认为CuldFube中的空字符串是什么?在这种情况下,这和空字符串有什么不同?谢谢,我今天就试试。谢谢,我今天就试试。