繁体   English   中英

如何使用AWS Cli启动具有自定义根卷ebs大小(大于8GB)的ec2实例

[英]How to launch ec2 instance with custom root volume ebs size (more than 8GB) using AWS Cli

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

我正在尝试这个命令,

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卷添加到实例)。

这在AWS CLI文档中有所介绍:

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

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

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

使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM