so you can delete SNS topics

This commit is contained in:
cktricky
2018-05-19 23:05:17 -03:00
parent 77f99e34ff
commit 1ed839cfda
2 changed files with 31 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ def list_sns_subscribers(topic,region):
result = client.list_subscriptions_by_topic(TopicArn=topic)
subscriptions = result['Subscriptions']
for sub in subscriptions:
print("Subscription Arn: {}".format(sub['SubscriptionArn']))
print("Protocol: {}".format(sub['Protocol']))
print("Endpoint: {}".format(sub['Endpoint']))
except botocore.exceptions.ClientError as e:
@@ -76,3 +77,21 @@ def delete_sns_topic(topic, region):
print("Unexpected error: {}" .format(e))
except KeyboardInterrupt:
print("CTRL-C received, exiting...")
def delete_sns_subscriber(endpoint, region):
try:
client = boto3.client('sns', region_name=region)
action = client.delete_endpoint(EndpointArn=endpoint)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'InvalidClientTokenId':
sys.exit("The AWS KEY IS INVALID. Exiting")
if e.response['Error']['Code'] == 'AccessDenied':
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))
else:
print("Unexpected error: {}" .format(e))
except KeyboardInterrupt:
print("CTRL-C received, exiting...")