I have the following mapping defined in my template
"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"]}
}
}}
However, validation fails and after looking at the docs I can see why. The mapping function wants a three tiered key and the value can only be a string or a list.
Is there anyway to do the above with a reference
or better mapping?
To accomplish a multi-level mapping, apply your nested Fn::FindInMap
intrinsic functions in the Resources or Outputs section directly.
Here's a complete working version of your example:
{
"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"}
]
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.