Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add tag while creating EBS snapshot using boto3

Is it possible to add a tag when invoking the create_snapshot() method in boto3? When I run the following code:

client = boto3.client('ec2')

root_snap_resp = client.create_snapshot(
    Description='My snapshot description',
    VolumeId='vol-123456',
    Tags=[{'Key': 'Test_Key', 'Value': 'Test_Value'}]
)

I get the following error:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "Tags", must be one of: DryRun, VolumeId, Description

Is the only way to add a tag after the fact using the create_tags() method?

like image 908
darksideofthesun Avatar asked Mar 10 '23 16:03

darksideofthesun


1 Answers

In April, 2018, the original answer (and the question itself) were made obsolete...

You can now specify tags for EBS snapshots as part of the API call that creates the resource or via the Amazon EC2 Console when creating an EBS snapshot.

https://aws.amazon.com/blogs/compute/tag-amazon-ebs-snapshots-on-creation-and-implement-stronger-security-policies/

...unless you are using an older version of an SDK that does not implement the feature.

The same announcement extended resource-level permissions to snapshots.

The underlying CreateSnapshot action in the EC2 API doesn't have any provision for adding tags simultaneously with the creation of the snapshot. You have to go back and tag it after creating it.

like image 192
Michael - sqlbot Avatar answered Mar 12 '23 05:03

Michael - sqlbot