【发布时间】:2017-01-19 02:54:15
【问题描述】:
我想从 Account1, region1 触发 Account2, region2 中的 Lambda 函数。
所以,我使用订阅了 HTTPS API 网关端点(POST 方法)的 SNS 主题,这将触发 Lambda。
问题是我不知道如何抓取到达 API Gateway 端点的 SNS POST 请求。
我正在尝试关注 AWS 文档中的 this guide。
我已经成功测试了 Gateway 和 Lambda 之间的连接。 我使用这个虚拟 JSON:
{
"type": "object",
"description": "A subscription confirmation message",
"properties": {
"SignatureVersion": {
"enum": [
"1"
],
"type": "string"
},
"Timestamp": {
"type": "string"
},
"MessageId": {
"type": "string",
"identity": true
},
"SubscribeURL": {
"type": "string"
},
"Token": {
"type": "string"
},
"Signature": {
"type": "string"
},
"Message": {
"minLength": 1,
"type": "string",
"maxLength": 4096
},
"Type": {
"enum": [
"SubscriptionConfirmation"
],
"type": "string"
},
"TopicArn": {
"type": "string",
"maxLength": 1224
}
}
}
我使用的测试 Lambda 是这样的:
import boto3,json
def handler(event, context):
#return event['properties']['SubscribeURL']
return event
文档声明here After you subscribe an HTTP/HTTPS endpoint, Amazon SNS sends a subscription confirmation message to the HTTP/HTTPS endpoint.
我不一定希望每次都有一段代码来确认订阅,因为我只会设置一次流程。但是,我不知何故需要获取订阅 URL 以确认订阅。
任何指针都会有所帮助!
【问题讨论】:
-
为什么不将 Lambda 函数作为事件源直接订阅到 SNS 主题,如此处所述? docs.aws.amazon.com/lambda/latest/dg/…
-
我试过了,但据我了解,SNS 主题和 Lambda 函数必须在同一区域。我的用例是对us-west-2中的RDS实例进行手动快照,将其与另一个帐户共享,因此它将在第二个帐户的us-west-2中可见,然后将其复制到us-east -1 在第二个帐户中。处理副本的 Lambda(根据文档)必须位于副本将存在的区域中。
标签: json amazon-web-services aws-lambda aws-api-gateway