Skip to content

Instantly share code, notes, and snippets.

@devxoul
Last active January 11, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/a99e55f48b55b6aff136 to your computer and use it in GitHub Desktop.
Save devxoul/a99e55f48b55b6aff136 to your computer and use it in GitHub Desktop.
Enable Amazon SNS endpoint.
from boto.sns import connect_to_region
AWS_ACCESS_KEY = ''
AWS_SECRET_KEY = ''
AWS_REGION = ''
ARN = ''
sns = connect_to_region(AWS_REGION,
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY)
def search(*tokens):
arns = []
for token in tokens:
response = sns.create_platform_endpoint(ARN, token)
arns.append(response['CreatePlatformEndpointResponse']
['CreatePlatformEndpointResult']
['EndpointArn'])
return arns
def enable(*tokens):
arns = search(*tokens)
for arn in arns:
sns.set_endpoint_attributes(arn, {'Enabled': True})
response = sns.get_endpoint_attributes(arn)
response = response['GetEndpointAttributesResponse']
response = response['GetEndpointAttributesResult']
response = response['Attributes']
enabled = response['Enabled']
print 'Enabled: {}'.format(enabled)
def prune():
next_token = None
while True:
response = sns.list_endpoints_by_platform_application(ARN, next_token)
response = response['ListEndpointsByPlatformApplicationResponse']
response = response['ListEndpointsByPlatformApplicationResult']
endpoints = response['Endpoints']
next_token = response['NextToken']
if not next_token:
return
for endpoint in endpoints:
if endpoint['Attributes']['Enabled'] == 'false':
sns.delete_endpoint(endpoint['EndpointArn'])
print "Delete " + endpoint['Attributes']['Token']
enable('token')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment