How to create AMI from EBS snapshot with AWS CLI

Viewed 1925

I know that AMI can be created from EBS snapshot on EC2 console.

I want to operate this AMI creation not on the AWS console but with the AWS CLI command.

The aws ec2 copy-image command does not have any EBS Snapshot option to specify. Is there any way to do this with CLI or calling APIs?

2 Answers

after I had the same problem and was looking for the simple example (because the documentation like linked in above is a little bit confused written) - and unfortunately could not find any, I post a simple example aws-cli call.

A real world example:

aws ec2 register-image --name "YOUR_DESCRIPTION" --region=eu-west-1 --description "AMI_from_snapshot_EBS" --block-device-mappings DeviceName="/dev/sda",Ebs={SnapshotId="snap-0070070007"} --root-device-name "/dev/sda1"

OUTPUT should be something like this:

{
    "ImageId": "ami-0022d44252254fffff7"
}
Related