diff --git a/ec2/ec2.py b/ec2/ec2.py index 8643308..39573d3 100644 --- a/ec2/ec2.py +++ b/ec2/ec2.py @@ -6,7 +6,8 @@ import pprint pp = pprint.PrettyPrinter(indent=5, width=80) -regions = ['us-east-1', 'us-west-2', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'eu-central-1', 'eu-west-1'] +#from http://docs.aws.amazon.com/general/latest/gr/rande.html +regions = ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'ap-northeast-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', ] # right now this will print a file with nothing if bad key, should fix at some point --otherwise can assume its a valid key # we are past the enumeration stage at this point @@ -52,4 +53,64 @@ def review_encrypted_volumes(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY): print e +def get_instance_details(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY): + try: + for region in regions: + client = boto3.client( + 'ec2', + aws_access_key_id = AWS_ACCESS_KEY_ID, + aws_secret_access_key = AWS_SECRET_ACCESS_KEY, + region_name=region + ) + + instances = client.describe_instances() + for r in instances['Reservations']: + for i in r['Instances']: + pp.pprint(i) + + except botocore.exceptions.ClientError as e: + print e + +#show volumes sorted by instanceId ex: instanceID-->multiple volumes less detail than get_instance_volume_details2 +def get_instance_volume_details(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY): + try: + for region in regions: + client = boto3.client( + 'ec2', + aws_access_key_id = AWS_ACCESS_KEY_ID, + aws_secret_access_key = AWS_SECRET_ACCESS_KEY, + region_name=region + ) + + instances = client.describe_instances() + for r in instances['Reservations']: + for i in r['Instances']: + volumes = client.describe_instance_attribute(InstanceId=i['InstanceId'], Attribute='blockDeviceMapping') + print ("Instance ID: {} \n" .format(i['InstanceId'])) + pp.pprint(volumes) + + except botocore.exceptions.ClientError as e: + print e + +#show volumes by instanceId but instanceID->volume1 of ID, instanceID->volume2 of ID but more details. +def get_instance_volume_details2(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY): + try: + for region in regions: + client = boto3.client( + 'ec2', + aws_access_key_id = AWS_ACCESS_KEY_ID, + aws_secret_access_key = AWS_SECRET_ACCESS_KEY, + region_name=region + ) + response = client.describe_volumes(Filters=[{ + 'Name' : 'status', + 'Values' : ['in-use'] + }])['Volumes'] + for volume in response: + print("InstandID:{} \n" .format(volume['Attachments'][0]['InstanceId'])) + pp.pprint(volume) + print("\n") + + except botocore.exceptions.ClientError as e: + print e diff --git a/ec2/ec2.pyc b/ec2/ec2.pyc index c60ab9c..a871bf3 100644 Binary files a/ec2/ec2.pyc and b/ec2/ec2.pyc differ diff --git a/ec2_get_all_instances.py b/ec2_get_all_instances.py new file mode 100644 index 0000000..056621d --- /dev/null +++ b/ec2_get_all_instances.py @@ -0,0 +1,23 @@ +''' +This file is used to list ec2 instances +''' + +import boto3 +import botocore + +import json +import urllib +import logging +import sys,os +import pprint + +pp = pprint.PrettyPrinter(indent=5, width=80) + +from ec2.ec2 import * + +#insert AWS key, will figure out how to pull this in from a single file for all scripts + +AWS_ACCESS_KEY_ID = '' +AWS_SECRET_ACCESS_KEY = '' + +get_instance_details(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) \ No newline at end of file diff --git a/ec2_get_instance_volumes.py b/ec2_get_instance_volumes.py new file mode 100644 index 0000000..cfd8a41 --- /dev/null +++ b/ec2_get_instance_volumes.py @@ -0,0 +1,25 @@ +''' +This file is used to list volumes of ec2 instances +''' + +import boto3 +import botocore + +import json +import urllib +import logging +import sys,os +import pprint + +pp = pprint.PrettyPrinter(indent=5, width=80) + +from ec2.ec2 import * + +#insert AWS key, will figure out how to pull this in from a single file for all scripts + +AWS_ACCESS_KEY_ID = '' +AWS_SECRET_ACCESS_KEY = '' + + +get_instance_volume_details(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) +get_instance_volume_details2(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) \ No newline at end of file diff --git a/ec2_review_encrypted_volumes.py b/ec2_review_encrypted_volumes.py index 4642eef..bb66f12 100644 --- a/ec2_review_encrypted_volumes.py +++ b/ec2_review_encrypted_volumes.py @@ -19,6 +19,6 @@ from ec2.ec2 import * #insert AWS key, will figure out how to pull this in from a single file for all scripts AWS_ACCESS_KEY_ID = '' -AWS_SECRET_ACCESS_KEY ='' +AWS_SECRET_ACCESS_KEY = '' review_encrypted_volumes(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) \ No newline at end of file