Div*_*ivy 6 amazon-ec2 amazon-web-services aws-ebs
我正在尝试使用AWS CLI启动ec2实例,但默认根卷仅为8GB。如何使用具有100GB根卷的CLI使用CLI启动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}]'
Run Code Online (Sandbox Code Playgroud)
我尝试添加以下参数,但无法正常工作。
--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大。或者,您想为当前使用电磁卷的AMI使用通用(SSD)卷。
将describe-images命令与要使用的AMI的映像ID一起使用,以查找其现有的块设备映射。您应该在输出中看到块设备映射:
{
"DeviceName": "/dev/sda1",
"Ebs": {
"DeleteOnTermination": true,
"SnapshotId": "snap-1234567890abcdef0",
"VolumeSize": 8,
"VolumeType": "standard",
"Encrypted": false
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过更改各个参数来修改上述映射。例如,要启动具有修改后的块设备映射的实例,请在run-instances命令中添加以下参数,以更改上述映射的卷大小和类型:
--block-device-mappings file://mapping.json
Run Code Online (Sandbox Code Playgroud)
其中mapping.json包含以下内容:
[
{
"DeviceName": "/dev/sda1",
"Ebs": {
"DeleteOnTermination": true,
"SnapshotId": "snap-1234567890abcdef0",
"VolumeSize": 100,
"VolumeType": "gp2"
}
}
]
Run Code Online (Sandbox Code Playgroud)
要在一个命令行上执行此操作,该命令应采用以下格式:
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
Run Code Online (Sandbox Code Playgroud)
请注意,设备名称需要与根设备名称匹配,您可以使用以下格式的命令找到根设备名称:
aws ec2 describe-images --image-id ami-0a5e707736615003c --region eu-west-1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1027 次 |
| 最近记录: |