问题描述
目前,如果我们要使用的设备添加到SNS应用:
Currently, If we want to add a device to an SNS application using:
ep = SNSConnection.create_platform_endpoint(app_arn,device_token,user_data)
有该设备已在过去已添加的选项。要验证设备是否已添加,我们使用的是:
There is an option that the device was already added in the past.To verify if the device is already added, we're using:
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
这是非常低效的,不能进行缩放。
which is very inefficient and can not be scaled.
是那里得到一个博托SNS功能的device_token并返回,如果存在endpoint_arn?(无如果没有)。
is there a boto sns function that get the device_token and returns the endpoint_arn if exists?(None if not).
推荐答案
亚马逊为您提供了错误信息阿尔恩。你可以从那里解析它。不是最优的,但可以节省一些分贝查找。
Amazon gives you the arn on the Error Message. You can parse it from there. Not optimal, but saves some db lookup.
错误:SNS错误 - 无法subcribe用户SNSInvalidParameter:无效的参数:令牌原因:端点ARN:AWS:SNS:美国朝东[的ARN关键休息]与同样已经存在,但不同的属性。下面是正则表达式准备好了一些咖啡
error: SNS ERROR - Could not subcribe user to SNSInvalidParameter: Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-[rest of the ARN Key] already exists with the same Token, but different attributes. Here is some coffe with regex ready to go
if err?
log.error "SNS ERROR - Could not subcribe user to SNS" + err
#Try to get arn from error
result = err.message.match(/Endpoint(.*)already/)
if result?.length
#Assign and remove leading and trailing white spaces.
result = result[1].replace /^\s+|\s+$/g, ""
log.debug "found existing arn-> #{result} "
这篇关于AWS博托SNS - 通过设备令牌获得endpoint_arn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!