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



我正试图使用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卷添加到实例中(

这在AWS CLI文档中有介绍:

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

启动具有修改的块设备映射的实例

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

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

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

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

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

最新更新