gpt4 book ai didi

amazon-web-services - 带有引用或顶级 Fn::FindInMap 的 CloudFormation 模板

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

我在模板中定义了以下映射

"Mappings": {
"TimeBasedAutoScale" : {
"days" : {
"weekend" : {"0":"off","1":"off","2":"off","3":"off","4":"off","5":"off","6":"off","7":"off","8":"off","9":"off","10":"off","11":"off","12":"off","13":"off","14":"off","15":"off","16":"off","17":"off","18":"off","19":"off","20":"off","21":"off","22":"off","23":"off"},
"weekday1" : {"0":"off","1":"off","2":"on","3":"on","4":"on","5":"on","6":"on","7":"on","8":"on","9":"on","10":"on","11":"on","12":"on","13":"on","14":"on","15":"on","16":"on","17":"on","18":"on","19":"on","20":"on","21":"on","22":"off","23":"off"},
"weekday2" : {"0":"off","1":"off","2":"off","3":"on","4":"on","5":"on","6":"on","7":"on","8":"on","9":"on","10":"on","11":"on","12":"on","13":"on","14":"on","15":"on","16":"on","17":"on","18":"on","19":"on","20":"on","21":"on","22":"off","23":"off"}
}
},
"TimeBasedSchedule": {
"6AMTimeBasedSchedule" : {
"schedule" : {
"Monday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Tuesday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Wednesday" :{ "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Thursday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Friday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Saturday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekend"]},
"Sunday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekend"]}
}
},
"7AMTimeBasedSchedule" : {
"schedule" : {
"Monday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Tuesday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Wednesday" :{ "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Thursday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Friday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekday1"]},
"Saturday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekend"]},
"Sunday" : { "Fn::FindInMap" : [ "TimeBasedAutoScale", "days", "weekend"]}
}
}}

但是,验证失败并且在looking at the docs之后我明白为什么。映射函数需要一个三层键,值只能是字符串或列表。

有没有办法通过引用或更好的映射来完成上述操作?

最佳答案

要完成多级映射,请应用嵌套 Fn::FindInMap Resources 中的内在函数或Outputs直接部分。

这是示例的完整工作版本:

Launch Stack

{
"Description": "Return 'on' or 'off' according to the provided schedule, hour of day, and day of week.",
"Mappings": {
"TimeBasedAutoScale": {
"weekend" : {"0":"off","1":"off","2":"off","3":"off","4":"off","5":"off","6":"off","7":"off","8":"off","9":"off","10":"off","11":"off","12":"off","13":"off","14":"off","15":"off","16":"off","17":"off","18":"off","19":"off","20":"off","21":"off","22":"off","23":"off"},
"weekday1" : {"0":"off","1":"off","2":"on","3":"on","4":"on","5":"on","6":"on","7":"on","8":"on","9":"on","10":"on","11":"on","12":"on","13":"on","14":"on","15":"on","16":"on","17":"on","18":"on","19":"on","20":"on","21":"on","22":"off","23":"off"},
"weekday2" : {"0":"off","1":"off","2":"off","3":"on","4":"on","5":"on","6":"on","7":"on","8":"on","9":"on","10":"on","11":"on","12":"on","13":"on","14":"on","15":"on","16":"on","17":"on","18":"on","19":"on","20":"on","21":"on","22":"off","23":"off"}
},
"TimeBasedSchedule": {
"6AMTimeBasedSchedule": {
"Monday": "weekday1",
"Tuesday": "weekday1",
"Wednesday": "weekday1",
"Thursday": "weekday1",
"Friday": "weekday1",
"Saturday": "weekend",
"Sunday": "weekend"
},
"7AMTimeBasedSchedule": {
"Monday": "weekday2",
"Tuesday": "weekday2",
"Wednesday": "weekday2",
"Thursday": "weekday2",
"Friday": "weekday2",
"Saturday": "weekend",
"Sunday": "weekend"
}
}
},
"Parameters": {
"Schedule": {
"Description": "Selected schedule",
"Type": "String",
"AllowedValues" : [ "6AMTimeBasedSchedule", "7AMTimeBasedSchedule" ],
"Default": "6AMTimeBasedSchedule"
},
"DayOfWeek": {
"Description": "Day of week",
"Type": "String",
"AllowedValues" : [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ],
"Default": "Monday"
},
"HourOfDay": {
"Description": "Hour of Day",
"Type": "Number",
"MinValue": "0",
"MaxValue": "23",
"Default": "0"
}
},
"Resources": {
"Dummy": {
"Type": "AWS::CloudFormation::WaitConditionHandle"
}
},
"Outputs": {
"Result": {
"Value": {
"Fn::FindInMap": [
"TimeBasedAutoScale",
{"Fn::FindInMap": ["TimeBasedSchedule", "6AMTimeBasedSchedule", {"Ref": "DayOfWeek"}]},
{"Ref": "HourOfDay"}
]
}
}
}
}

关于amazon-web-services - 带有引用或顶级 Fn::FindInMap 的 CloudFormation 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38776170/

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