amazon-web-services - aws CloudFormation AWS::EC2::Instance BlockDeviceMappings 和卷

标签 amazon-web-services amazon-ec2 aws-cloudformation

我对两个 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 卷的哪种方法更好吗?这两种方法有什么区别?

最佳答案

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

关于amazon-web-services - aws CloudFormation AWS::EC2::Instance BlockDeviceMappings 和卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15391718/

相关文章:

python - 使用 crond 运行时,boto 与 AWS 的连接挂起

python - pymysql.err.InternalError : (1049, "Unknown database")

python - AWS Elastic Beanstalk 使用 Python 2 和 Python 3 出错?

amazon-web-services - 如何使用 Cognito LOGOUT 端点真正注销?

shell - 已安装软件包时避免 yum 错误

mysql - 通过ec2 beantalk实例访问RDS

java - 如何使用 key 文件通过 Java 数据库连接连接到 AWS 数据库

amazon-web-services - AWS Cloudformation - 对现有资源进行逆向工程

amazon-web-services - 资源 arn :aws:cloudformation:us-east-1:aws:transform 的权限问题

docker - 容器化和编排使用哪个工具以及原因