gpt4 book ai didi

amazon-web-services - 使用 Fn::GetAtt 的 AWS CloudFormation 条件失败

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

我正在尝试使用 Fn::GetAtt 内部函数创建条件 block ,但失败并出现以下错误 -

“模板验证错误:模板格式错误:未解析的依赖项。无法引用模板的条件 block 中的资源。”

My condition - 
"SomeCondition":{
"Fn::Equals":[
{
"Fn::GetAtt":[
"CustomResource",
"ID"
]
},
"SOME-UUID"
]
}

有人可以建议解决此问题的方法吗?我想使用条件在我的用户数据部分动态选择脚本。

最佳答案

“无法引用模板的条件 block 中的资源”错误消息在 Condition Functions 中进行了解释。文档:

Note

You can only reference other conditions and values from the Parameters and Mappings sections of a template. For example, you can reference a value from an input parameter, but you cannot reference the logical ID of a resource in a condition.

对于在用户数据部分动态选择脚本的解决方法,您可以将条件逻辑从 CloudFormation 直接移动到用户数据脚本中,例如使用 Bash conditional constructFn::Sub intrinsic function :

UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -xe
if [[ ${CustomResource.ID} == "SOME-UUID" ]]; then
# some commands
else
# other commands
fi

关于amazon-web-services - 使用 Fn::GetAtt 的 AWS CloudFormation 条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41171163/

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