python 启用Amazon SNS端点。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 启用Amazon SNS端点。相关的知识,希望对你有一定的参考价值。
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')
以上是关于python 启用Amazon SNS端点。的主要内容,如果未能解决你的问题,请参考以下文章
如何通过电子邮件订阅带有电子邮件端点的 Amazon SNS 主题?
在 iOS 设置中更改通知时,Amazon SNS 如何禁用/重新启用设备?
从 Amazon SNS(APNS 生产)获取“EndpointDisabled”
Amazon SNS GCM/FCM 消息负载
使用 Amazon SNS 处理 GCM 规范 ID
使用 Amazon SNS 时无法接收到 iOS 设备的推送通知