SNS 应用程序事件从端点获取用户数据

SNS Application Events get user data from endpoint

我有一个亚马逊 SNS 应用程序 (GCM)。我已将其配置为在创建新平台端点时触发 lambda 函数执行。我需要将平台端点添加到我的用户数据库中。与端点关联的用户名作为 "User Data" 发送。

我想使用 lambda 函数将端点 arn 添加到用户数据库条目。

当我将 JSON 数据发送到 lambda 时,我唯一有用的是新令牌的端点 ARN。不发送用户数据。因此,我需要能够使用 boto 进行查找,但我一直无法找到执行此操作的方法。我将如何在给定端点 ARN 的情况下查找用户数据?

JSON 提供给 lambda 函数的数据:

{
  "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