2014-05-23 23 views
4

試圖使用Fn ::內FN :: FindInMap如下加入,:AWS Cloudformation:Fn ::在Fn :: FindInMap語句中加入?

"SubnetId": { 
    "Fn::FindInMap": [ 
     { 
      "Ref": "OrganizationName" 
     }, 
     "AZ", 
     { 
      "Fn::Join": [ 
       "", 
       [ 
        { 
         "Ref": "Environment" 
        }, 
        { 
         "Ref": "Member1AZ" 
        } 
       ] 
      ] 
     } 
    ] 
} 

的單位名稱,環境和Member1AZ是所有參數。本質上,它應該掛鉤到我的映射和生產,例如:

"SubnetId" : { "Fn::FindInMap" : [ "Organization2", "AZ", "prod1c" ]} 

但是,它似乎並沒有服用從FN ::加入作爲新生力量:: FindInMap,一個單一實體輸出如果我硬編碼該模板的該部分,則會正確驗證。

A client error (ValidationError) occurred when calling the ValidateTemplate operation: Template error: every Fn::FindInMap object requires three parameters, the map name, map key and the attribute for return value 

我的映射如下:在這個

Mappings" : { 
     "OrganizationDefaults" : { 
      "AZ" : { 
       "prod1a" : "subnet-foobar1", 
       "qa1a" : "subnet-foobar2", 
       "prod1c" : "subnet-foobar3", 
       "qa1c" : "subnet-foobar4" 
      } 
     }, 
     "OrganizationTwo" : { 
      "AZ" : { 
       "prod1a" : "subnet-foobar5", 
       "qa1a" : "subnet-foobar6", 
       "prod1c" : "subnet-foobar7", 
       "qa1c" : "subnet-foobar8" 
      } 
     }, 
}, 

任何人的幫助,或者有前做同樣的事情?我需要爲列出的任何組織使用相同的模板,因此如果我能夠做到,Mappings應該爲我解決這個問題。

回答

1

我建議你重構你的映射以避免嵌套的Fn :: Join。

Mappings" : { 
     "OrganizationDefaults" : { 
      "1a" : { 
       "prod" : "subnet-foobar1", 
       "qa" : "subnet-foobar2" 
      }, 
      "1c" 
       "prod" : "subnet-foobar3", 
       "qa" : "subnet-foobar4" 
      } 
     }, 
     "OrganizationTwo" : { 
      "1a" : { 
       "prod" : "subnet-foobar5", 
       "qa" : "subnet-foobar6" 
      }, 
      "1c" : { 
       "prod" : "subnet-foobar7", 
       "qa" : "subnet-foobar8" 
      } 
     }, 
}, 

這簡化了您的參考。

"SubnetId" : { "Fn::FindInMap" : [ { "Ref" : "OrganizationName" }, { "Ref" : "Member1AZ" }, { "Ref" : "Environment" }]} 
1

雖然我@Jason同意你的情況你的地圖佈局的重構是最適合你的解決方案,存在這樣的情況在CloudFormation地圖的二維限制可以限制,所以我將發佈這裏可能的解決方案。

由於這個職位的日期,Fn::FindInMap內在功能僅支持以下嵌套函數:

  • Fn::FindInMap
  • Ref

使用Join會給你稍微有點隱蔽的錯誤你在上面發帖。但是,因爲你可以窩FindInMap電話,你可以通過創建另一個查找地圖實現地圖中的「第三漁政船」:

Mappings" : { 
    "OrganizationDefaults" : { 
     "AZ" : { 
      "prod1a" : "subnet-foobar1", 
      "qa1a" : "subnet-foobar2", 
      "prod1c" : "subnet-foobar3", 
      "qa1c" : "subnet-foobar4" 
     } 
    }, 
    "OrganizationTwo" : { 
     "AZ" : { 
      "prod1a" : "subnet-foobar5", 
      "qa1a" : "subnet-foobar6", 
      "prod1c" : "subnet-foobar7", 
      "qa1c" : "subnet-foobar8" 
     } 
    }, 
    "EnvMemberMap" : { 
     "prod": { 
      "1a" : "prod1a", 
      "1c" : "prod1c", 
     }, 
     "qa": { 
      "1a" : "qa1a", 
      "1c" : "qa1c", 
     }  
    } 
}, 

,然後執行地圖檢索這樣的:

"SubnetId": { 
    "Fn::FindInMap": [ 
     { 
      "Ref": "OrganizationName" 
     }, 
     "AZ", 
     { 
      "Fn::FindInMap": [ 
       "EnvMemberMap", 
       { 
        "Ref": "Environment" 
       }, 
       { 
        "Ref": "Member1AZ" 
       } 
      ] 
     } 
    ] 
}