Domanda

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 ?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top