gpt4 book ai didi

json - 需要使用一个 AWS CloudFormation 模板为不同环境启动多个实例

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

我需要构建 3 种不同类型的环境,每种环境都有不同数量的实例,要使用 JSON 中的单个 CF 模板启动。例如:第 1 个 ENV 需要 2 个实例,第 2 个 ENV 需要 4 个实例,第 3 个 ENV 需要 8 个实例。请指教

我正在从用户那里获取输入以选择 ENV 类型,并据此启动实例的数量。

无法在 EC2 属性下提及实例计数,并且无法使用 Fn::If 更改条件

最佳答案

您可以将映射参数结合使用,如下所示:

"AWSTemplateFormatVersion": "2010-09-09",
"Description": "ALB and ASG",
"Mappings": {
"Environment": {
"i": {
"InstanceType": "t2.small",
"Count": 2
},
"s": {
"InstanceType": "t3.small",
"Count": 3
},
"p": {
"InstanceType": "m1.small",
"Count": 4
}
}
},
"Parameters": {
"ShortEnv": {
"AllowedValues": [
"i",
"p",
"s"
],
"ConstraintDescription": "must define the current environment",
"Description": "Environment type",
"Type": "String"
}
}

然后可以在相关资源属性中使用它:

"InstanceType": {
"Fn::FindInMap": [
"Environment",
{
"Ref": "ShortEnv"
},
"InstanceType"
]
},
"DesiredCapacity": {
"Fn::FindInMap": [
"Environment",
{
"Ref": "ShortEnv"
},
"InstanceType"
]
}

关于json - 需要使用一个 AWS CloudFormation 模板为不同环境启动多个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56171451/

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