I'm trying to launch an ec2 instance using AWS CLI, but default root volume is 8GB only. how can I launch ec2 instance using CLI with say 100GB of root volume?
I'm trying this command,
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}]'
I tried adding below parameters, but its not working.
--block-device-mapping DeviceName=/dev/sda1,Ebs={VolumeSize=100}
--block-device-mapping /dev/sda1=:100:false
--block-device-mappings <value>
(adds secondary EBS volume to the instance).
This is covered in the AWS CLI Documentation here:
https://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html
To launch an instance with a modified block device mapping
You can change individual characteristics of existing AMI block device mappings to suit your needs. Perhaps you want to use an existing AMI, but you want a larger root volume than the usual 8 GiB. Or, you would like to use a General Purpose (SSD) volume for an AMI that currently uses a Magnetic volume.
Use the describe-images command with the image ID of the AMI you want to use to find its existing block device mapping. You should see a block device mapping in the output:
You can modify the above mapping by changing the individual parameters. For example, to launch an instance with a modified block device mapping, add the following parameter to your run-instances command to change the above mapping's volume size and type:
Where mapping.json contains the following:
To do this on one command line, the command should be in the format:
Note that the device name needs to match the root device name, which you can find with a command in the format: