SNS应用程序事件从端点获取用户数据
问题描述:
我有一个亚马逊SNS应用程序(GCM)。我已经将其配置为在创建新平台端点时触发一个lambda函数来执行。我需要将平台端点添加到我的用户数据库。与端点关联的用户名将作为“用户数据”发送。SNS应用程序事件从端点获取用户数据
我想使用lambda函数将端点arn添加到用户数据库条目。
当我得到JSON数据到lambda时,唯一有用的东西是新标记的端点ARN。用户数据未发送。因此,我需要能够使用boto查找它,但我一直无法找到一种方法来做到这一点。如何查找给定端点ARN的用户数据?给拉姆达功能可按
JSON数据:
{
"Type" : "Notification",
"MessageId" : "afb28e95-f8cb-5622-a6ad-dccb37f6b07a",
"TopicArn" : "<Censored>",
"Subject" : "EndpointCreated event message",
"Message" : "{\"EndpointArn\":\"<Censored>\",\"EventType\":\"EndpointCreated\",\"Resource\":\<Censored>\",\"Service\":\"SNS\",\"Time\":\"2017-10-16T15:15:09.097Z\",\"Type\":\"EndpointCreated\"}",
"Timestamp" : "2017-10-16T15:15:09.181Z",
"SignatureVersion" : "1",
"Signature" : "<Censored>",
"SigningCertURL" : "<Censored>",
"UnsubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=<Censored>",
"Attributes" : {
"EndpointArn" : "<Censored>",
"EventType" : "EndpointCreated",
"Resource" : "<Censored>",
"Service" : "SNS",
"Time" : "2017-10-16T15:15:09.097Z",
"Type" : "EndpointCreated"
},
"MessageAttributes" : {
"AWS.SNS.OldAttributeTransport" : {"Type":"String","Value":"{\"EndpointArn\":\"<Censored>\",\"EventType\":\"EndpointCreated\",\"Resource\":\"<Censored>\",\"Service\":\"SNS\",\"Time\":\"2017-10-16T15:15:09.097Z\",\"Type\":\"EndpointCreated\"}"}
}
}
答
Boto3具有SNS方法听起来就像你在找什么:GetEndpointAttributes
。
import boto3
client = boto3.client('sns')
response = client.get_endpoint_attributes(EndpointArn="INSERT-ARN")
print(response["Attributes"]["CustomUserData"])
HTH
文档中发现here。
我不相信我忽略了这一点。我昨天盯着那个网页几个小时,试图一切。谢谢! – Reid