gpt4 book ai didi

amazon-web-services - AWS CloudFormation : Provide an attribute itself (not the value! ) 有条件

转载 作者:行者123 更新时间:2023-12-03 07:34:22 25 4
gpt4 key购买 nike

基于 CloudFormation 模板中的参数,我尝试为资源提供属性。我的意思并不是为该属性提供一个值,而是决定是否应将该属性传递给资源。具体来说,我尝试对 AWS::IAM::Role 资源的属性 RoleName 执行此操作。我尝试了以下方法:

"Conditions": {
"MyCondition": {
"Fn::Equals": [
{
"Ref": "OptionalRoleName"
},
""
]
}
},
...
"Parameters": {
"OptionalRoleName": {
"AllowedPattern": "^$|[\\w+=,.@-]+",
"ConstraintDescription": "Please use only upper and lowercase alphanumeric characters with no spaces and any of the following characters: _+=,.@-.",
"Default": "",
"Description": "Optional fixed Role Name",
"Type": "String"
}
},
...
"Properties": {
"RoleName": {
"Fn::If": [
"MyCondition",
{"Ref": "OptionalRoleName"},
{"Ref": "AWS::NoValue"}
]
},
....

但是如果不满足条件,在执行过程中AWS会提示RoleName不能为空字符串。因此,在字符串属性的情况下,AWS::NoValue 似乎评估为空字符串。有没有办法解决这个问题?

谢谢!

最佳答案

您的条件不正确;如果未指定 OptionalRoleName,则条件计算结果为 true,但您希望对此进行否定。指定如下条件应该会给你你想要的行为:

"MyCondition": {
"Fn::Not": {
"Fn::Equals": [
{
"Ref": "OptionalRoleName"
},
""
]
}
}

关于amazon-web-services - AWS CloudFormation : Provide an attribute itself (not the value! ) 有条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68313190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com