我正在 AWS Cloudformation 中创建一个堆栈来构建 EC2 实例。因此我需要用户输入某些参数。我的任务是在不同类型之间进行选择。根据这些类型,相应的值将显示在另一个列表中。
我想我可以用以下代码(包括映射)解决这个问题:
"Parameters": {
"ProjectName": {
"Description": "Enter the project name.",
"Type": "String"
},
"InstanceType": {
"Description": "Select your Instance type.",
"AllowedValues": [
"t3",
"m5",
"r5"
],
"Default": "t3",
"Type": "String"
},
"InstanceTypeSize": {
"Description": "Select your Instance type size.",
"AllowedValues":{
"Fn::Split" : [
",",
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
]
},
"Type": "String"
}
},
"Mappings": {
"Params": {
"t3": {
"values": "t3.nano,t3.micro,t3.small,t3.medium,t3.large,t3.xlarge,t3.2xlarge"
},
"m5": {
"values": "m5.large,m5.xlarge,m5.2xlarge,m5.4xlarge,m5.8xlarge,m5.12xlarge,m5.16xlarge,m5.24xlarge,m5.metal"
},
"r5": {
"values": "r5.large,r5.xlarge,r5.2xlarge,r5.4xlarge,r5.8xlarge,r5.12xlarge,r5.16xlarge,r5.24xlarge,r5.metal"
}
}
}
Split
方法返回字符串列表。参数 "AllowedValues"
需要“包含参数允许的值列表的数组”。
有人知道我做错了什么或者错误出在哪里吗?问题是否有替代解决方案?
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
您必须将实例类型定义为一个大数组
"Parameters": {
"ProjectName": {
"Description": "Enter the project name.",
"Type": "String"
},
"InstanceType": {
"Description": "Select your Instance type.",
"AllowedValues": [t3.nano,t3.micro,t3.small,t3.medium,t3.large,t3.xlarge,t3.2xlarge,m5.large,m5.xlarge,m5.2xlarge,m5.4xlarge,m5.8xlarge,m5.12xlarge,m5.16xlarge,m5.24xlarge,m5.metal,r5.large,r5.xlarge,r5.2xlarge,r5.4xlarge,r5.8xlarge,r5.12xlarge,r5.16xlarge,r5.24xlarge,r5.metal
],
"Default": "t3",
"Type": "String"
},
"InstanceTypeSize": {
"Description": "Select your Instance type size.",
"AllowedValues":{
"Fn::Split" : [
",",
{ "Fn::FindInMap": [
"Params",
{"Ref": "InstanceType"},
"values"
]}
]
},
"Type": "String"
}
}