gpt4 book ai didi

amazon-web-services - AWS Cloudformation如何使用条件资源作为其他资源的 DependsOn

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

我正在尝试使用 IAMInstanceprofile 的可选值创建 EC2 实例。当 createiam 为 False 时,我期望 ec2stack 在没有 iam 的情况下创建,当其为 True 时,它​​应该等待 iamstack 并使用其值。

     "Parameters": {
"createiam" : {
"Type" : "String",
"Default" : "False"
}
},

"Conditions" : {
"Create_iam" : {"Fn::Equals" : [{"Ref" : "createiam"}, "True"]}
},

"Resources" : {
"iamstack" : {
"Type" : "AWS::CloudFormation::Stack",
"Condition": "Create_iam"
},
"ec2stack": {
"Type" : "AWS::CloudFormation::Stack",
"DependsOn" : "iamstack"
}
}

在使用 crateiam 选项 False 运行堆栈时,出现错误,提示未找到 iamstack 资源。有没有办法为 Dependson 值添加条件?

最佳答案

我可以通过 WaitConditionHandle 来实现这一点。

在这里找到引用资料。

  1. Stack overflow question
  2. Blog link with explination

现在的代码流程:


"Parameters": {
"createiam" : {
"Type" : "String",
"Default" : "False"
}
},

"Conditions" : {
"Create_iam" : {"Fn::Equals" : [{"Ref" : "createiam"}, "True"]}
},

"Resources" : {
"IAMWaithandle": {
"Condition": "Create_iam",
"DependsOn": "iamstack",
"Type": "AWS::CloudFormation::WaitConditionHandle"
},
"WaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle"
},
"IAMWaitcondiftion": {
"Type": "AWS::CloudFormation::WaitCondition",
"Properties": {
"Handle": {
"Fn::If": [
"Create_iam",
{
"Ref": "IAMWaithandle"
},
{
"Ref": "WaitHandle"
}
]
},
"Timeout": "1",
"Count": 0
}
},
"iamstack" : {
"Type" : "AWS::CloudFormation::Stack",
"Condition": "Create_iam"
},
"ec2stack": {
"Type" : "AWS::CloudFormation::Stack",
"DependsOn" : "IAMWaitcondiftion"
}
}

关于amazon-web-services - AWS Cloudformation如何使用条件资源作为其他资源的 DependsOn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66479302/

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