Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto3 can't delete AWS tags

boto3 mentioned on Github that they added support for deleting tags. However, when I execute the code below, it throws an exception:

ec2 = boto3.resource('ec2', region_name=aws_region)
ec2.delete_tags(Resources=[instance.id],Tags=[{"Key": non_compliant_tag_name}])

'ec2.ServiceResource' object has no attribute 'delete_tags'

$ pip show boto3
Name: boto3
Version: 1.4.4

What am I doing wrong?

like image 866
buildmaestro Avatar asked Jun 07 '17 00:06

buildmaestro


1 Answers

The delete_tags() method should be called on a client object rather than a resource object:

import boto3
client = boto3.client('ec2', region_name='ap-southeast-2')
...
client.delete_tags(Resources=[instance.id],Tags=[{"Key": non_compliant_tag_name}])
like image 148
John Rotenstein Avatar answered Sep 19 '22 13:09

John Rotenstein