SNS应用程序事件从端点

时间:2017-10-16 16:01:32

标签: lambda aws-lambda boto boto3 amazon-sns

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

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

当我将jSON数据传递给lambda时,我唯一有用的是新令牌的端点ARN。不发送用户数据。因此我需要能够使用boto查找它,但我无法找到这样做的方法。如何在给定端点ARN的情况下查找用户数据?

给予lambda funciton的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\"}"}
  }
}

enter image description here

1 个答案:

答案 0 :(得分:1)

Boto3有一个SNS方法听起来像你正在寻找的东西:GetEndpointAttributes

import boto3
client = boto3.client('sns')
response = client.get_endpoint_attributes(EndpointArn="INSERT-ARN")
print(response["Attributes"]["CustomUserData"])

HTH

找到文档here