创建块设备时使用!FindInMap

时间:2019-04-20 16:20:43

标签: amazon-cloudformation

所以我只是在创建磁盘时尝试使用FindInMap。

我得到了结构,但出现了错误:

  

“属性BlockDeviceMappings的值必须为列表类型”

很明显,我不完全了解其布局。

只需尝试我能想到的一切。.不幸的是,AWS的示例主要参考了将其用于区域。.如您所见,它没有太大帮助。

 ec2Map:                         ---(my map)
    test:                         ----(outter key)
      InstanceType: t2.small
      volsize: 20                ----(inner key)
    dev:
      InstanceType: t2.small
      volsize: 40

Note: there is parameter that references 'myec2instances' so I can pick the size in a drop down.

#here is where I am lost. How to I  reference the other items needed like device name and volumetype? 

So I get rid of the error mentioned above..


 BlockDeviceMappings: !FindInMap
        - ec2Map
        - !Ref 'myec2instance'
        - volsize
           DeviceName: "/dev/sdf"
      #       Ebs:
      #         VolumeSize: 
      #         VolumeType: gpa

我基本上是想做到这一点,所以在配置测试ec2时,它会增加20gb的额外容量,而对于开发人员来说,它将有40gb的容量。

1 个答案:

答案 0 :(得分:1)

您需要在结构中向下移动!FindInMap并重复该操作,如下所示:

BlockDeviceMappings:
  - DeviceName: '/dev/sdf' # additional volume
    Ebs:
      VolumeSize: !FindInMap [ec2Map, !Ref myec2instance, volsize]
      VolumeType: !FindInMap [ec2Map, !Ref myec2instance, voltype]
      ...