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

时间:2013-03-13 16:59:59

标签: amazon-web-services amazon-ec2

我对两个AWS :: EC2 :: Instance属性感到困惑: BlockDeviceMappingsVolumes

我已多次阅读文档,但仍然不太了解其中的差异。

这是我的模板:

 {
 "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"
         }
     }
 }}

这里我创建了3卷。 2,

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

和另一个:

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

CloudFormation运行良好,但我没有看到差异。

有人能告诉我哪种方式更适合向EC2实例添加EBS卷,这两种方法有什么区别?

1 个答案:

答案 0 :(得分:11)

使用BlockDeviceMappings,您不仅可以安装临时存储ebs。 卷只是ebs卷,并提供更好的选项(如选择AZ,或者如果要使用PIOP,则指定IOP)。 如果您想要的只是简单的ebs卷,那么没有区别。