issues with ec2 instance tagging with python script

0 votes
```

#!/usr/bin/env python3

import string

import boto3

import sys

import argparse

instance_id = sys.argv[1].split(',')

tagname = sys.argv[2]

tagvalue = sys.argv[3]

ec2= boto3.resource('ec2', region_name='us-west-1')

print(instance_id)

def tag_instance(instance_id,tagname,tagvalue):

TAGS = [

{

'Key': tagname,

'Value': tagvalue

}

]

#instances = ec2.instances(instance_id)

#instances = []

#instances.append(instance_id)

#print(instances)

instances = ec2.instances(instance_id)

print(instances)

for instance in instances:

instance.create_tags(Tags=TAGS)

print(f'Tags successfully added to the instance {instance.id}')

#print(f'EC2 instance {instance.id}" information:')

tag_instance(instance_id,tagname,tagvalue)

```

getting error

TypeError: 'ec2.instancesCollectionManager' object is not callable
Oct 19, 2022 in Python by Tony

edited 5 days ago 4 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP