0
votes

I'm trying to mount multiple EBS volumes to my EC2 instance using cloudformation, but for some reason, only the last EBS volume that I specify gets mounted.

EG:
NewEC2Instance:
    Type: AWS::EC2::Instance
    DependsOn: OldSecurityGroup
    Properties:
      ImageId: !Ref pImageId
      InstanceType: !Ref pInstanceType
      BlockDeviceMappings:
        -
          DeviceName: /dev/sda1
          Ebs:
            VolumeSize: 10
          DeviceName: /dev/sdf
          Ebs:
            VolumeSize: 11
            Encrypted: true
          DeviceName: /dev/sdg
          Ebs:
            VolumeSize: 12
            Encrypted: true 
          DeviceName: /dev/sdh
          Ebs:
            VolumeSize: 100
            Encrypted: true 

For the above code, only the 100Gb /dev/sdh gets created.

I think Cloudformation is overwriting the EBS volumes.

Anyone know why? Please help!

1
Please paste into notepad to look at codeswap709

1 Answers

4
votes

You miss a - in front of each device name. Like so:

  BlockDeviceMappings:
  - DeviceName: "/dev/xvda"
    Ebs:
      VolumeSize: 16
      VolumeType: gp2
  - DeviceName: "/dev/xvdf"
    Ebs:
      VolumeSize: 12
      VolumeType: gp2

With only one - you were actually defining an array with a single element with conflicting keys, the default behavior for yaml is to use the last key it find in the object.