首页 > 解决方案 > 使用 serverless-offline-sns 通过来自托管 AWS SNS 的 SNS 消息调用 serverless-offline Lambda 函数

问题描述

serverless-offline-sns在其文档中说,为了收听 AWS 上托管的 SNS,您需要以下内容:

custom:
  serverless-offline-sns:
    localPort: ${env:LOCAL_PORT}
    remotePort: ${env:SNS_SUBSCRIBE_REMOTE_PORT}
    host: 0.0.0.0
    sns-subscribe-endpoint: ${env:SNS_SUBSCRIBE_ENDPOINT}
    sns-endpoint: ${env:SNS_ENDPOINT}

但我不知道从哪里获得所需的环境值:

标签: amazon-web-servicesaws-lambdaamazon-snsserverless-framework

解决方案


阅读完源代码后,我能够在 AWS 中托管一个 SNS 来触发我的本地功能,因为文档不是很清楚

这是我使用的配置:

serverless-offline-sns:
    sns-endpoint: sns.${self:provider.region}.amazonaws.com
    sns-subscribe-endpoint: <ngrok_url>
    remotePort: 80
    localPort: <ngrok_port>
    accountId: ${self:provider.accountId}

示例用法:

  1. 使用 ngrok:ngrok http 4002

  2. 像这样设置配置:

serverless-offline-sns:
    sns-endpoint: sns.${self:provider.region}.amazonaws.com
    sns-subscribe-endpoint: xxxxxxxx.ngrok.io
    remotePort: 80
    localPort: 4002
    accountId: ${self:provider.accountId}

推荐阅读