[英]aws cloudformation how can I use conditions in the mapping block?
Hi I have the following mapping that I wanted to use condition statements in:嗨,我有以下映射,我想在其中使用条件语句:
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]
As you can see I am trying to sigv4 sign to a different region depending on the value of an input param in the prod version of my site.正如您所看到的,我正在尝试根据我网站 prod 版本中输入参数的值将 sigv4 签名到不同的区域。 However after reading the docs it seems you cant use condition statements in the Mappings block of your template.
但是, 在阅读文档后,您似乎无法在模板的 Mappings 块中使用条件语句。 How/where should I go about checking the
IsChinaSite
condition?我应该如何/去哪里检查
IsChinaSite
条件?
I image you can mix an If and FindInMap to get the result you want我想你可以混合一个 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]
Ended up having to just split out the regions into their own mapping under each env.最终不得不在每个环境下将区域拆分为自己的映射。 Wound up with this:
结束了这个:
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
This solution worked for me because thankfully I was only parameterizing with 2 dimensions (the max/min dimensions required to make a cloudformation mapping) but that was kind of dumb luck.这个解决方案对我有用,因为幸运的是我只使用 2 个维度(制作云形成映射所需的最大/最小维度)进行参数化,但那是一种愚蠢的运气。 Had I been in a situation where I needed to deploy in multiple envs, with multiple types of sites, AND each type of site had some sort of sub-type, I would have been scr---d.
如果我处于需要在多个环境中部署的情况,具有多种类型的站点,并且每种类型的站点都有某种子类型,我会被 scr --- d。 I still think the right answer here is something that can support x^n number of dimensions so I don't think I am going to accept my own answer but I wanted to share my solution to my problem.
我仍然认为这里的正确答案是可以支持 x^n 个维度的东西,所以我认为我不会接受我自己的答案,但我想分享我对问题的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.