CloudFormation中的AWS API网关方法响应

时间:2018-04-18 06:21:07

标签: aws-api-gateway amazon-cloudformation

我正在尝试设置我的API网关,因此它有这个简单的方法响应:  
 

Method Response

Method Response Details

我正在使用CloudFormation并且我一直遇到错误。我相信这很简单,但是我花了几个小时阅读文档后陷入困境。这是我的方法资源(在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

我需要MethodResponse属性吗?

2 个答案:

答案 0 :(得分:3)

好吧,看起来我只需添加这个:

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

答案 1 :(得分:-2)

是的,没错。您需要添加以下内容:

MethodResponses:

  • StatusCode:200

    ResponseModels:

      application/json: 'Empty'