简体   繁体   中英

AttributeError: 'EC2' object has no attribute 'tag_resources'

I run following code and get error:

#!python -u

from boto3 import client

def is_tags():
 response = client('ec2', 'us-east-1').tag_resources(
 ResourceARNList=[
 'arn:aws:ec2:us-east-1::image/ami-55ef662f'
    ],
    Tags=[
        {
         'Key': 'Name',
         'Value': 'john',
        },
    ],
    )    
if __name__ == '__main__':
    is_tags()

It is throwing the following error:

AttributeError: 'EC2' object has no attribute 'tag_resources'

What am I doing wrong?

You are using the library incorrectly, the client object has no attribute called tag_resources , due to which the call to it is failing.

You can refer the correct usage from the boto3 documentation for Tag in EC2 :

import boto3

ec2 = boto3.resource('ec2', 'us-east-1')
tag = ec2.Tag('resource_id','key','value')

EDIT : I am not sure if there is a single API for tagging multiple type of resources that consistently works. You seem to be following this API , in which case, you have to define your client correctly , like:

client = boto3.client('resourcegroupstaggingapi', 'us-east-1')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM