Fixes issue #50

This commit is contained in:
cktricky
2018-06-03 00:14:27 -04:00
committed by Kenneth Toler
parent 159a9d862c
commit f94482eb28
3 changed files with 35 additions and 9 deletions

View File

@@ -11,20 +11,25 @@ regions = ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1', '
session = boto3.Session()
credentials = session.get_credentials()
AWS_ACCESS_KEY_ID = credentials.access_key
topics_list = {}
def list_sns_topics():
def list_sns_topics(should_i_print=True):
title = "SNS Topics"
print(title)
print("-" * len(title))
if should_i_print:
print(title)
print("-" * len(title))
try:
for region in regions:
client = boto3.client('sns', region_name=region)
topics = client.list_topics()
print(region)
print("=" * len(region))
if should_i_print:
print(region)
print("=" * len(region))
if topics['Topics']:
for topic in topics['Topics']:
print(topic)
topics_list[region] = topics['Topics']
if should_i_print:
for topic in topics['Topics']:
print(topic)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'InvalidClientTokenId':
sys.exit("The AWS KEY IS INVALID. Exiting")
@@ -79,6 +84,20 @@ def delete_sns_topic(topic, region):
except KeyboardInterrupt:
print("CTRL-C received, exiting...")
def list_all_sns_subscribers():
print("Scanning regions....")
list_sns_topics(False)
for region,topics in topics_list.items():
for topic in topics:
region_title = "Region: {}".format(region)
print(region_title)
print("=" * len(region_title))
list_sns_subscribers(topic['TopicArn'],region)
def delete_sns_subscriber(endpoint, region):
try:
client = boto3.client('sns', region_name=region)
@@ -90,8 +109,8 @@ def delete_sns_subscriber(endpoint, region):
print('{} : Is NOT a root key' .format(AWS_ACCESS_KEY_ID))
elif e.response['Error']['Code'] == 'SubscriptionRequiredException':
print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID))
#elif e.response['Error']['Code'] == 'InvalidParameter':
# print('The region you provided ({}) is invalid for the Subscriber endpoint. Are you sure this subscriber exists in this region?'.format(region))
elif e.response['Error']['Code'] == 'InvalidParameter':
print('The region you provided ({}) is invalid for the Subscriber endpoint. Are you sure this subscriber exists in this region?'.format(region))
else:
print("Unexpected error: {}" .format(e))
except KeyboardInterrupt: