python - AWS Boto instance tagging -


all struggling add name tags newly created ec2 instance,

is there way in aws identify last created instance?

reservations = ec2.get_all_instances() instance = reservations[0].instances[0] create_tags([instance.id], {"name": tag}) 

this isn't setting tags deployed instance.

to name newly created instance, add name tag after creating vm:

import boto.ec2 conn = boto.ec2.connect_to_region("eu-west-1",aws_access_key_id='key',aws_secret_access_key='sectret') reservations = conn.run_instances("ami-a10897d6", min_count=1, max_count=1, key_name="key", security_group_ids=["sg-123"], instance_type="t2.micro", subnet_id="subnet-123") instance = reservations.instances[0] conn.create_tags([instance.id], {"name":"foo"}) 

alternatively, if know excactly start time, can use filters parameter * wildcard. more dynamic example may be:

from datetime import datetime = datetime.utcnow() filter_now = "%s*" % (now.strftime("%y-%m-%dt%h:%m")) reservations = conn.get_all_instances(filters={"launch_time":filter_now}) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -