【发布时间】:2014-03-06 14:22:45
【问题描述】:
目前,如果我们想使用以下方式将设备添加到 SNS 应用程序:
ep = SNSConnection.create_platform_endpoint(app_arn,device_token,user_data)
有一个选项是该设备已在过去添加。 为了验证设备是否已添加,我们使用:
def is_device_registered(device_token):
list_of_endpoints = SNSConnection.list_endpoints_by_platform_application(AC.INPLAY_CHAT_APPLICATION_SNS_ARN)
all_app_endpoints = list_of_endpoints['ListEndpointsByPlatformApplicationResponse']['ListEndpointsByPlatformApplicationResult']['Endpoints']
for ep in all_app_endpoints:
ep_device_token = ep['Attributes']['Token']
if device_token == ep_device_token:
endpoint_arn = ep['EndpointArn']
print 'Found an endpoint for device_token: %s, entry:%s' % (device_token,endpoint_arn)
return endpoint_arn
return None
效率非常低,无法扩展。
是否有一个 boto sns 函数可以获取 device_token 并返回 endpoint_arn(如果存在)? (如果不是,则无)。
【问题讨论】:
-
嘿阿米特 - 你有没有找到最好的方法来处理这个?您是存储端点 arn 还是每次使用令牌查找它?如果您找到了“正确”的方法,请回答您自己的问题
-
我们可以选择将它存储在 DB/Redis 中,但由于数据存储在 AWS SNS 中,我们认为使用 API 从那里检索它会很有用(在这种情况下为 boto)
标签: amazon-web-services boto amazon-sns