【问题标题】:Integrate API Gateway with SNS using Cloudformation使用 Cloudformation 将 API Gateway 与 SNS 集成
【发布时间】:2018-01-29 03:26:21
【问题描述】:

我正在尝试使用 Cloudformation 将 API 网关方法集成到 SNS 主题,但无法弄清楚 Uri 属性应该是什么样子。

对于连接到 Lambda,它看起来像:

"Integration": {
      "IntegrationHttpMethod": "POST",
      "Type": "AWS",
      "Uri": {
        "Fn::Join": [
          "",
          [
            "arn:aws:apigateway:",
            {
              "Ref": "AWS::Region"
            },
            ":lambda:path/2015-03-31/functions/",
            {
              "Fn::GetAtt": [
                "SomeLambdaFunction",
                "Arn"
              ]
            },
            "/invocations"
          ]
        ]
      }

SNS 的等价物是什么样的?

【问题讨论】:

    标签: amazon-web-services aws-api-gateway amazon-cloudformation


    【解决方案1】:

    将主题、主题和消息设置为请求参数的集成模板如下所示:

      ApiGatewayGETMethod:
        Type: AWS::ApiGateway::Method
        Properties:
          AuthorizationType: NONE
          HttpMethod: GET
          RequestParameters:
            method.request.querystring.message: false
            method.request.querystring.subject: false
            method.request.querystring.topic: false
          Integration:
            Type: AWS
            Credentials:
              Fn::GetAtt: [ GatewayRole, Arn ]
            Uri:
              Fn::Join:
                - ""
                - - "arn:aws:apigateway:"
                  - Ref: AWS::Region
                  - ":sns:action/Publish"
            IntegrationHttpMethod: GET
            RequestParameters:
              integration.request.querystring.TopicArn: "method.request.querystring.topic"
              integration.request.querystring.Subject: "method.request.querystring.subject"
              integration.request.querystring.Message: "method.request.querystring.message"
            IntegrationResponses:
              - StatusCode: 200
                ResponseTemplates:
                  application/json: '{"status":"OK"}'
          MethodResponses:
            - StatusCode: 200
          ResourceId:
            Fn::GetAtt: [ ApiGatewayRestApi , RootResourceId ]
          RestApiId: !Ref ApiGatewayRestApi
    

    可以使用以下语法调用此实现:

    https://abc123456.execute-api.eu-central-1.amazonaws.com/x
              ?topic=arn:aws:sns:eu-central-1:111111:sampletopic
              &message=samplemesage
              &subject=samplesubject
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 2016-03-16
      • 2017-04-27
      • 1970-01-01
      • 2019-06-22
      • 2020-11-20
      • 2019-06-02
      相关资源
      最近更新 更多