将 SNS 消息发布到 HTTPS Api 网关端点以触发 Lambda 函数 [英] Posting SNS message to HTTPS Api Gateway endpoint to trigger Lambda function

查看:30
本文介绍了将 SNS 消息发布到 HTTPS Api 网关端点以触发 Lambda 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Account1, region1 触发 Account2, region2 中的 Lambda 函数.

I want to trigger a Lambda function in Account2, region2 from Account1, region1 .

因此,我使用订阅了 HTTPS API 网关端点(POST 方法)的 SNS 主题,这将触发 Lambda.

So, I use an SNS topic subscribed to an HTTPS API Gateway endpoint (POST method), which will trigger the Lambda.

问题是我不知道如何抓取到达 API Gateway 端点的 SNS POST 请求.

The problem is that I do not know how to grab the SNS POST request arriving at the API Gateway endpoint .

我正在尝试遵循本指南 来自 AWS 文档.

I am trying to follow this guide from the AWS docs.

我已经成功测试了 Gateway 和 Lambda 之间的连接.我使用这个虚拟 JSON:

I have successfully test the connection between Gateway and Lambda. I use this dummy 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 是这样的:

And the test Lambda I use is this:

import boto3,json

def handler(event, context):

    #return event['properties']['SubscribeURL']
    return event

文档状态 此处 在您订阅 HTTP/HTTPS 终端节点后,Amazon SNS 会向 HTTP/HTTPS 终端节点发送订阅确认消息.

我不一定要每次都有一段代码来确认订阅,因为我只会设置一次流程.但是,我以某种方式需要获取订阅 URL 以确认订阅.

I don't necessarily want to have a piece of code to confirm the subscription every time because I will only set the flow once. But, I somehow need to take the subscription URL in order to confirm the subscription.

任何指针都会有帮助!

推荐答案

你想具体解决什么问题?您应该能够使用 临时凭据.您还可以直接从您的 Lambda 函数,因此您可能不需要 API 网关.

What problem are you trying to solve specifically? You should be able to invoke a Lambda function across accounts using temporary credentials. You could also publish to an SNS topic directly from your Lambda function, so you probably don't need API Gateway.

这篇关于将 SNS 消息发布到 HTTPS Api 网关端点以触发 Lambda 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆