Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws CloudFormation AWS::EC2::Instance BlockDeviceMappings and Volumes

I am sort of confused about two AWS::EC2::Instance properties: BlockDeviceMappings and Volumes.

I have read documentation a number of times but still don't really understand the difference.

Here is my template:

 {
 "AWSTemplateFormatVersion" : "2010-09-09",

 "Description" : "kappoowTest",

 "Mappings" : {
     "AmazonLinuxAMI" : {
         "eu-west-1" :
             { "AMI" : "ami-d8f9f1ac" },
         "us-west-1" :
             { "AMI" : "ami-b63210f3" }
     }
 },

 "Resources" : {
     "SomeInstance" :{
         "Type" : "AWS::EC2::Instance",
         "Properties" : {
             "AvailabilityZone" : "eu-west-1a",
             "BlockDeviceMappings" : [
                 {
                     "DeviceName" : "/dev/sdc",
                     "Ebs" : { "VolumeSize" : "50" }
                 },
                 {
                     "DeviceName" : "/dev/sdd",
                     "Ebs" : { "VolumeSize" : "100" }
                 }
             ],
             "DisableApiTermination" : "true",
             "EbsOptimized" : "true",
             "ImageId" : { "Fn::FindInMap" : [ "AmazonLinuxAMI", { "Ref" : "AWS::Region" }, "AMI" ]},
             "InstanceType" : "m1.large",
             "KeyName" : "mongo_test",
             "Monitoring" : "true",
             "SecurityGroups" : [ "default" ],
             "Volumes" : [
                 { "VolumeId" : { "Ref" : "NewVolume" }, "Device" : "/dev/sdk" }
             ]
         }
     },

     "NewVolume" : {
         "Type" : "AWS::EC2::Volume",
         "Properties" : {
             "Size" : "100",
             "AvailabilityZone" : "eu-west-1a"
         }
     }
 }}

Here I have created 3 volumes. 2 with

 "BlockDeviceMappings" : [
                 {
                     "DeviceName" : "/dev/sdc",
                     "Ebs" : { "VolumeSize" : "50" }
                 },
                 {
                     "DeviceName" : "/dev/sdd",
                     "Ebs" : { "VolumeSize" : "100" }
                 }
             ]

and another one with:

"Volumes" : [
    { "VolumeId" : 
          { "Ref" : "NewVolume" }, "Device" : "/dev/sdk" }
 ]

CloudFormation ran fine, but I fail to see the difference.

Could someone tell me what which way is better of adding EBS volumes to EC2 instance and what is the difference between these two methods ?

like image 290
Katafalkas Avatar asked Mar 13 '13 16:03

Katafalkas


1 Answers

With BlockDeviceMappings you can mount ephemeral storage not only ebs. Volumes is only ebs volumes, and provides better options (like choosing the AZ, or specifying the IOPs if you want to use PIOPs). If all what you want is simple ebs volumes, then there is no difference.

like image 200
nnahum Avatar answered Oct 07 '22 19:10

nnahum