[英]aws cloudformation how can I use conditions in the mapping block?
嗨,我有以下映射,我想在其中使用條件語句:
Conditions:
IsChinaSite:
!Equals [!Ref SiteType, 'ChinaSite']
Mappings:
Environment2Env:
Develop:
ENV: Dev
ApiRegion: us-east-1 # There is no test CN data so we are going to keep using test US data in test envs
Test:
ENV: Qual
ApiRegion: us-east-1
Staging:
ENV: Test
ApiRegion: us-east-1
Production:
ENV: Prod
FleetApiRegion: !If[IsChinaSite, ap-northeast-1, us-east-1]
正如您所看到的,我正在嘗試根據我網站 prod 版本中輸入參數的值將 sigv4 簽名到不同的區域。 但是, 在閱讀文檔后,您似乎無法在模板的 Mappings 塊中使用條件語句。 我應該如何/去哪里檢查IsChinaSite
條件?
我想你可以混合一個 If 和 FindInMap 來得到你想要的結果
Conditions:
IsChinaSite:
!Equals [!Ref SiteType, 'ChinaSite']
Mappings:
Environment2Env:
Develop:
ENV: Dev
ApiRegion: us-east-1
Test:
ENV: Qual
ApiRegion: us-east-1
Staging:
ENV: Test
ApiRegion: us-east-1
USProduction:
Env: Prod
ApiRegion: us-east-1
ChinaProduction:
ENV: Prod
ApiRegion: ap-northeast-1
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone:
!If
- IsChainSite
- !FindInMap [Environment2Env, ChinaProduction, ApiRegion]
- !FindInMap [Environment2Env, USProduction, ApiRegion]
最終不得不在每個環境下將區域拆分為自己的映射。 結束了這個:
Mappings:
Environment2Env:
Develop:
ENV: Dev
Test:
ENV: Qual
Staging:
ENV: Test
USProduction:
Env: Prod
ChinaProduction:
ENV: Prod
Develop:
ROW: us-east-1
ChinaSite: us-east-1
Test:
ROW: us-east-1
ChinaSite: us-east-1
Staging:
ROW: us-east-1
ChinaSite: us-east-1
Production:
ROW: us-east-1
ChinaSite: ap-northeast-1
這個解決方案對我有用,因為幸運的是我只使用 2 個維度(制作雲形成映射所需的最大/最小維度)進行參數化,但那是一種愚蠢的運氣。 如果我處於需要在多個環境中部署的情況,具有多種類型的站點,並且每種類型的站點都有某種子類型,我會被 scr --- d。 我仍然認為這里的正確答案是可以支持 x^n 個維度的東西,所以我認為我不會接受我自己的答案,但我想分享我對問題的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.