Last active
May 29, 2017 23:05
-
-
Save evandhoffman/9664264 to your computer and use it in GitHub Desktop.
Export EC2 instances to CSV.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Based on the script found here: http://cloudbuzz.wordpress.com/2011/02/15/336/ | |
from boto.ec2 import EC2Connection | |
csv_file = open('instances.csv','w+') | |
def process_instance_list(connection): | |
map(build_instance_list,connection.get_all_instances()) | |
def build_instance_list(reservation): | |
map(write_instances,reservation.instances) | |
def write_instances(instance): | |
environment = '-' | |
if 'environment' in instance.tags: | |
environment = instance.tags['environment'] | |
# For more parameters to the boto.ec2.instance.Instance object, see here: http://boto.readthedocs.org/en/latest/ref/ec2.html#module-boto.ec2.instance | |
# In our case, we use the "environment" tag to distinguish between dev/staging/prod instances. | |
csv_file.write("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n"%(instance.id,instance.tags['Name'],environment,instance.private_ip_address, | |
instance.state,instance.placement,instance.architecture, instance.vpc_id, instance.kernel, instance.instance_type, instance.image_id, instance.launch_time)) | |
csv_file.flush() | |
if __name__=="__main__": | |
connection = EC2Connection(aws_access_key_id='xxxxxxx',aws_secret_access_key='yyyyyyyyyyy') | |
process_instance_list(connection) | |
csv_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rajaniyer123 you may need to configure boto libarary and run this script
http://stackoverflow.com/questions/14351373/how-can-i-install-boto-library-on-windows-for-python