Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29245

Unable to add tag to instance python

$
0
0

I'm creating an ec2 instance in python boto3 with this code:

image_id = input("Enter the image id: ")
max_count = input("Enter the number of instances you want: ")
instance_type = input("Enter the instance type: ")
key_name = input("Enter the key name you want to use: ")
name_tag = input("Enter the host name: ")
instance = ec2_resource.create_instances(
    ImageId=image_id,
    MinCount=1,
    MaxCount=max_count,
    InstanceType=instance_type,
    KeyName=key_name
)

But when I try to apply a name tag with this code:

instance.add_tag('Name', name_tag)

I get an error that says:

Traceback (most recent call last):
  File ".\aws_create_ec2_simple.py", line 134, in <module>
    main()
  File ".\aws_create_ec2_simple.py", line 130, in main
    create_instances()
  File ".\aws_create_ec2_simple.py", line 125, in create_instances
    instance.add_tag('Name', name_tag)
AttributeError: 'list' object has no attribute 'add_tag'

How can I do this correctly?


Viewing all articles
Browse latest Browse all 29245

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>