1

I want to delete a tag from EBS volume using boto3/lambda. At this doc https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#volume I see 'create_tags()' only. It is suitable for modifying tags and e.g. to set an empty value but I need to remove the tag completely.

I tried create_tags() using an empty value and just create_tags() with all tags I need to keep and excluding ones but it does not work: the tags I want to delete remain untouched.

    tagRes = boto3.resource('ec2', region_name=region);
    volume = tagRes.Volume(id);
    ...
    tagsToKeep.append({'Key': tagName, 'Value': 'keep it'})
    ...
    ret = volume.create_tags(
        Resources=[id],
        Tags=tagsToKeep
    );

So, how to delete a tag from EBS volume?

Putnik
  • 2,095
  • 3
  • 23
  • 40

1 Answers1

2

It works in quite unexpected way: despite you create tags using resource, you have to delete them using client:

id = 'vol-5e0e9c3333'
tagRes = boto3.client('ec2', region_name=region)
ret = tagRes.delete_tags(
    Resources=[id],
    Tags=[{'Key': 'tag_name_to_del' }]
);
Putnik
  • 2,095
  • 3
  • 23
  • 40