【问题标题】:How to launch ec2 instance with custom root volume ebs size (more than 8GB) using AWS Cli如何使用 AWS Cli 启动具有自定义根卷 ebs 大小(超过 8GB)的 ec2 实例
【发布时间】:2019-04-21 11:50:50
【问题描述】:

我正在尝试使用 AWS CLI 启动一个 ec2 实例,但默认根卷仅为 8GB。如何使用 CLI 和 100GB 的根卷启动 ec2 实例?

我正在尝试这个命令,

aws ec2 run-instances --image-id ami-xxxxx --count 1 --instance-type t2.micro \
--subnet-id xxxxxxx \
--key-name my-key \
--security-group-ids sg-xxxxxx \
--no-associate-public-ip-address \
--user-data file://test.sh \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=test-server}]'

我尝试添加以下参数,但它不起作用。

  • --block-device-mapping DeviceName=/dev/sda1,Ebs={VolumeSize=100}
  • --block-device-mapping /dev/sda1=:100:false
  • --block-device-mappings <value>(向实例添加辅助 EBS 卷)。

【问题讨论】:

  • 您遇到了一些错误吗?另外,您为什么要尝试以两种不同的方式指定卷大小?这:--block-device-mapping /dev/sda1=:100:false 是不推荐使用的语法,你应该只使用--block-device-mapping DeviceName=/dev/sda1,Ebs={VolumeSize=100}

标签: amazon-web-services amazon-ec2 aws-ebs


【解决方案1】:

这在此处的 AWS CLI 文档中有介绍:

https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html

使用修改后的块储存设备映射启动实例

您可以更改现有 AMI 块储存设备映射的各个特征以满足您的需求。也许您想使用现有的 AMI,但您需要比通常的 8 GiB 更大的根卷。或者,您想为当前使用磁性卷的 AMI 使用通用 (SSD) 卷。

使用 describe-images 命令和您要用于查找其现有块储存设备映射的 AMI 的映像 ID。您应该在输出中看到块设备映射:

{
  "DeviceName": "/dev/sda1",
  "Ebs": {
    "DeleteOnTermination": true,
    "SnapshotId": "snap-1234567890abcdef0",
    "VolumeSize": 8,
    "VolumeType": "standard",
    "Encrypted": false
  }
}

您可以通过更改各个参数来修改上述映射。例如,要启动具有修改的块储存设备映射的实例,请将以下参数添加到您的 run-instances 命令以更改上述映射的卷大小和类型:

--block-device-mappings file://mapping.json

其中 mapping.json 包含以下内容:

[
  {
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "DeleteOnTermination": true,
      "SnapshotId": "snap-1234567890abcdef0",
      "VolumeSize": 100,
      "VolumeType": "gp2"
    }
  }
]

要在一个命令行上执行此操作,命令应采用以下格式:

aws ec2 run-instances --block-device-mapping DeviceName=/dev/xvda,Ebs={VolumeSize=100} --image-id ami-0a5e707736615003c --region eu-west-1 --instance-type t3.micro

请注意,设备名称需要与根设备名称匹配,可以通过以下格式的命令找到:

aws ec2 describe-images --image-id ami-0a5e707736615003c --region eu-west-1

【讨论】:

    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 2011-08-25
    • 2021-02-15
    相关资源
    最近更新 更多