Launch the EC2 instance using the selected base image (in this case Ubuntu 20.04). This will form the foundation on which we’ll provision the new image.
xxxxxxxxxx
aws ec2 run-instances \
--region $REGION \
--image-id $AMI_ID_BASE \
--count 1 \
--block-device-mappings file://device-mapping.json \
--instance-type $TYPE \
--key-name $KEYPAIR \
>$JSON_EC2
Wait for the instance to be running before retrieving the its final parameters.
xxxxxxxxxx
aws ec2 wait instance-status-ok \
--region $REGION \
--instance-ids $INSTANCE_ID
aws ec2 describe-instances \
--region $REGION \
--instance-ids $INSTANCE_ID \
>$JSON_EC2
Now request the full description.
xxxxxxxxxx
aws ec2 create-image \
--region $REGION \
--instance-id $INSTANCE_ID \
--name "$AMI_NAME_TARGET" \
--no-reboot \
>$JSON_AMI
xxxxxxxxxx
$ aws ec2 run-instances \
--image-id ami-40d28157 \
--count 1 \
--instance-type g2.2xlarge \
--key-name cli_keypair \
--security-group-ids sg-28e2c455