Moneer81
Moneer81

Reputation: 305

AWS API Gateway Method Response in CloudFormation

I am trying to set up my API Gateway so it has this simple method response:

Method Response

Method Response Details

And I am using CloudFormation and I keep running into errors. I believe this is pretty simple but I am stuck after spending hours reading docs. Here is my method resource (in YAML):

MyMethod:
Type: "AWS::ApiGateway::Method"
Properties:
  AuthorizationType: "NONE"
  HttpMethod: "GET"
  Integration:
    Type: AWS
    Credentials: !GetAtt MyRole.Arn
    IntegrationHttpMethod: "POST"
    Uri:
      Fn::Join: [ "", [ "arn:aws:apigateway:", Ref: "AWS::Region", ":states:action/SendTaskSuccess" ] ]
    PassthroughBehavior: WHEN_NO_TEMPLATES
    RequestTemplates:
      application/json: |
        {
           "output": "\"Approve link was clicked.\"",
           "taskToken": "$input.params('taskToken')"
        }
    IntegrationResponses:
      - StatusCode: 200
        ResponseTemplates: {"application/json": "$input.json('$.body')"}
   RequestParameters:
    method.request.querystring.taskToken: false
  OperationName: succeed
  ResourceId: !Ref MyResource
  RestApiId: !Ref MyApi

Do I need a MethodResponse property?

Upvotes: 9

Views: 10631

Answers (3)

abhaysingh
abhaysingh

Reputation: 7

  ApiPATCH:
    Type: AWS::ApiGateway::Method
    Properties:
      RestApiId: APIGateway
      ResourceId: ProxyResourceROOT
      HttpMethod: PATCH  
      AuthorizationType: NONE
       Integration:
        Type: AWS
        IntegrationHttpMethod: POST
        Uri: !Join 
          - ''
          - - 'arn:aws:apigateway:'
            - !Ref 'AWS::Region'
            - ':lambda:path/2015-03-31/functions/'
            - !GetAtt 
              - LambdaFunction
              - Arn
            - /invocations
        IntegrationResponses:
          - StatusCode: 200
      MethodResponses:
        - StatusCode: 200
          ResponseModels:
            application/json: 'Empty'

Upvotes: -1

Anoop
Anoop

Reputation: 428

Yes that's right. You need to add the following:

MethodResponses:

  • StatusCode: 200

    ResponseModels:

      application/json: 'Empty'
    

Upvotes: -4

Moneer81
Moneer81

Reputation: 305

Ok it looks like I just had to add this:

MethodResponses:
    - StatusCode: 200
      ResponseModels: { "application/json": "Empty" }

Upvotes: 13

Related Questions