I can initiate a spot EC2 instance using the AWS command line tool.
aws ec2 request-spot-instances \
--spot-price 0.01 \
--instance-count 1 \
--launch-specification \
"{ \
\"ImageId\":\"ami-009d6802948d06e52\", \
\"InstanceType\":\"t2.small\", \
\"KeyName\":\"dec15a\", \
\"UserData\":\"`base64 -w 0 userdata.sh`\" \
}"
But how do I change the Volume size? I know the following code needs to be added to launch-specification. But I am not sure exactly where to add it.
"BlockDeviceMappings": [
{
"Ebs": {
"VolumeSize": 107374182400,
"VolumeType": "standard"
}
}
],
Update:
Why does the same command does not work using "file" like this?
# cat specification.json
{
"ImageId":"ami-009d6802948d06e52",
"InstanceType":"t2.small",
"KeyName":"dec15a",
"UserData":"`base64 -w 0 userdata.sh`",
"BlockDeviceMappings": [ {
"DeviceName":"/dev/xvda",
"Ebs": {
"VolumeSize": 100,
"VolumeType": "standard"
}
} ]
}
# aws ec2 request-spot-instances --spot-price "1.050" --instance-count 1 --type "one-time" --launch-specification file://specification.json
An error occurred (InvalidParameterValue) when calling the RequestSpotInstances operation: Invalid BASE64 encoding of user data