While creating an image (AMI) in AWS using boto3 lib, providing the following parameters:
ec2.create_image(Name=name, BlockDeviceMappings=[{'DeviceName':device_name,'Ebs':{'SnapshotId':snapshot_id, 'DeleteOnTermination': delete_on_term,
'VolumeSize':10, 'VolumeType':'gp2'}}])
I'm getting this error: Missing required parameter in input: "InstanceId"
But when I create an image from the User Interface, no Instance Id is required.
In the picture below, you can see that I can create the image from 'Snapshots' page, without specifying instance Id.
Is anyone aware of a workaround? Thanks.
use this function register_image to create image from snapshots
response = client.register_image(
ImageLocation='string',
Architecture='i386'|'x86_64'|'arm64',
BlockDeviceMappings=[
{
'DeviceName': 'string',
'VirtualName': 'string',
'Ebs': {
'DeleteOnTermination': True|False,
'Iops': 123,
'SnapshotId': 'string',
'VolumeSize': 123,
'VolumeType': 'standard'|'io1'|'gp2'|'sc1'|'st1',
'Encrypted': True|False,
'KmsKeyId': 'string'
},
'NoDevice': 'string'
},
],
Description='string',
DryRun=True|False,
EnaSupport=True|False,
KernelId='string',
Name='string',
BillingProducts=[
'string',
],
RamdiskId='string',
RootDeviceName='string',
SriovNetSupport='string',
VirtualizationType='string'
)