Skip to content

Instantly share code, notes, and snippets.

@cktricky
Created January 25, 2017 17:08
Show Gist options
  • Save cktricky/0fa3b13ca4306bcd1ec384e88eac3f55 to your computer and use it in GitHub Desktop.
Save cktricky/0fa3b13ca4306bcd1ec384e88eac3f55 to your computer and use it in GitHub Desktop.
Evaluate EBS Volumes Encryption Status
import boto3
import pprint
# MAKE SURE YOU CHANGE THESE VALUES OR THE TOOL WON'T WORK.
access_key_id = 'replace me'
secret_access_key = 'replace me'
'''
This file is used to list EBS volumes and whether or not they are encrypted. This is only for "in-use" (running) volumes.
'''
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']
not_encrypted = []
encrypted = []
print("Working... This may take a few....")
with open("volumes_list.txt", "w") as fout:
for region in regions:
client = boto3.client(
'ec2',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key,
region_name=region
)
response = client.describe_volumes(Filters=[{
'Name' : 'status',
'Values' : ['in-use']
}])['Volumes']
for volume in response:
if volume['Encrypted']:
encrypted.append(volume['VolumeId'])
else:
not_encrypted.append(volume['VolumeId'])
fout.write("\nEncrypted: " + str(volume['Encrypted']))
for attachments in volume['Attachments']:
fout.write("\nInstance ID: " + attachments['InstanceId'])
fout.write("\nVolume ID: " + volume['VolumeId'])
fout.write("\nRegion: " + region)
fout.write("\n" + "-" * 40)
fout.write("\nNot encrypted: " + str(len(not_encrypted)) + "\n")
fout.write(pprint.pformat(not_encrypted))
fout.write("\nEncrypted: " + str(len(encrypted)) + "\n")
fout.write(pprint.pformat(encrypted))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment