3

I'm trying to integrate an API Gateway method to a SNS Topic using Cloudformation, but can't figure out how the Uri property should look like.

For connecting to Lambda it looks something like:

"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"
          ]
        ]
      }

What would the equivalent for SNS look like?

appelblim
  • 65
  • 6

1 Answers1

3

An integration template where topic, subject and message are set as request parameter would look like this:

  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

This implementation can be called with the following syntax:

https://abc123456.execute-api.eu-central-1.amazonaws.com/x
          ?topic=arn:aws:sns:eu-central-1:111111:sampletopic
          &message=samplemesage
          &subject=samplesubject
jens walter
  • 13,269
  • 2
  • 56
  • 54