[英]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.