-
Notifications
You must be signed in to change notification settings - Fork 0
/
sns_auditor
47 lines (41 loc) · 1.68 KB
/
sns_auditor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import boto
import boto.ec2
import boto.ec2.cloudwatch
import boto.sns
import string
import os
import sys
import re
import csv
import json
import ConfigParser
import time
home = os.path.expanduser("~")
file_path = "%s/.aws/profile" % home
cp = ConfigParser.ConfigParser()
cp.read(file_path)
for section in cp.sections():
for name, value in cp.items(section):
if name == 'aws_access_key_id':
os.environ['aws_access_key_id'] = value
A_KEY = os.environ['aws_access_key_id']
elif name == 'aws_secret_access_key':
os.environ['aws_secret_access_key'] = value
S_KEY = os.environ['aws_secret_access_key']
ec2_conn = boto.ec2.EC2Connection(A_KEY, S_KEY)
region = ec2_conn.get_all_regions()
for acct_id in ec2_conn.get_all_security_groups(groupnames='default'):
aws_account_id = acct_id.owner_id
for r in boto.sns.regions():
#This is because those regions break boto
if r.name == 'us-gov-west-1' or r.name == 'eu-central-1' or r.name == 'cn-north-1':
continue
sns = boto.connect_sns(A_KEY, S_KEY, region=r)
sns_derp = sns.get_all_subscriptions()
for k,v in sns_derp.iteritems():
asdf = sns_derp['ListSubscriptionsResponse']
if sns_derp['ListSubscriptionsResponse']['ListSubscriptionsResult']['Subscriptions']:
print aws_account_id, asdf['ListSubscriptionsResult']['Subscriptions'][0]['Endpoint'], asdf['ListSubscriptionsResult']['Subscriptions'][0]['TopicArn']
else:
continue