3
votes

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

2 Answers

6
votes

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"
}
1
votes

From Creating an Amazon EBS-Backed Linux AMI - Amazon Elastic Compute Cloud:

To create an AMI from a snapshot using the command line

You can use one of the following commands. For more information about these command line interfaces, see Accessing Amazon EC2.

The register-image documentation page says:

You can also use RegisterImage to create an Amazon EBS-backed Linux AMI from a snapshot of a root device volume.