2017-10-16 108 views
0

我有一個亞馬遜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\"}"} 
 
    } 
 
}

enter image description here

回答

1

Boto3具有SNS方法聽起來就像你在找什麼:GetEndpointAttributes

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

HTH

文檔中發現here

+0

我不相信我忽略了這一點。我昨天盯着那個網頁幾個小時,試圖一切。謝謝! – Reid

相關問題