I am using boto3 with python3 for aws usage, in the aws console there is a very simple option for creating an image from a running / stopped ec2 instance. I am looking for something similar in the boto3 SDK, the closest this I found is how to create an image from the EBS volume like so:
session = boto3.Session(...)
ec2 = session.client("ec2")
ec2.create_image(...)
as explained here
I would like to save the need to find out the volume ID for the instance, and just use the instance ID, is that possible?
I tried to follow this Using this code:
ec2.create_image(instance_id)
But got this error
TypeError: create_image() only accepts keyword arguments.
You should be able to simply pass an Instance ID, using the following:
ec2.create_image(InstanceId=instance_id, Name="abc")
.
Note that this will attempt to reboot your EC2 instance. If you don't want the instance to reboot, use:
ec2.create_image(InstanceId=instance_id, NoReboot=True, Name="abc")
When trying the same i got an error ->
"AttributeError: 'ec2.ServiceResource' object has no attribute 'create_image'"
so my suggestion is use
"boto3.client('ec2').create_image" instead of "ec2.create_image"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With