我正在尝试使用 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。
使用带有要用于查找其现有块储存设备映射的 AMI 的镜像 ID 的 describe-images 命令。您应该在输出中看到一个块设备映射:
{
"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
关于amazon-web-services - 如何使用 AWS Cli 启动具有自定义根卷 ebs 大小(超过 8GB)的 ec2 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53369224/