【问题标题】:Posting SNS message to HTTPS Api Gateway endpoint to trigger Lambda function将 SNS 消息发布到 HTTPS Api 网关端点以触发 Lambda 函数
【发布时间】: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


【解决方案1】:

您想具体解决什么问题?您应该能够使用 temporary credentials 跨账户调用 Lambda 函数。您也可以直接从 Lambda function 发布到 SNS 主题,因此您可能不需要 API Gateway。

【讨论】:

  • 我有两个帐户。我想要来自俄勒冈州第一个账户的 SNS 来触发弗吉尼亚州第二个账户中的 Lambda 函数。我真的不在乎手段。我只是在寻找一种方法。
  • 见上面的链接。您将需要 SNS 来触发同一区域中的 Lambda 函数。通过该 Lambda 函数,您可以假定其他/账户区域中的临时凭证并直接调用第二个 Lambda 函数。
猜你喜欢
  • 1970-01-01
  • 2021-10-18
  • 1970-01-01
  • 2016-03-05
  • 2015-10-12
  • 2019-05-12
  • 2019-01-28
  • 2020-07-08
  • 2019-03-19
相关资源
最近更新 更多