【问题标题】:cloudformation apigateway missing HTTP Status: Proxycloudformation apigateway 缺少 HTTP 状态:代理
【发布时间】:2022-01-13 01:30:45
【问题描述】:

我正在使用 cloudformation 建立一个 API Gateway 资源,我注意到 Method Response 字段不包含 HTTP Status: Proxy,就像您从控制台创建代理资源时那样。

我的 CF 代码:

  Api:
    Type: AWS::ApiGateway::RestApi
    Properties:
      EndpointConfiguration:
        Types:
          - 'PRIVATE'
      Name: 'why_did_aws_have_to_crash_today_APIG'
  Resource:
    Type: 'AWS::ApiGateway::Resource'
    Properties:
      ParentId: !GetAtt Api.RootResourceId
      PathPart: '{proxy+}'
      RestApiId: !Ref Api
  Method:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      RestApiId: !Ref Api
      ResourceId: !Ref Resource
      HttpMethod: ANY
      AuthorizationType: NONE
      Integration:
        IntegrationHttpMethod: ANY
        Type: AWS_PROXY
        Uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:execute-api:us-east-1:why-did-aws-have-to-crash-today/invocations

【问题讨论】:

  • 那么你的问题是什么? API 不起作用?有什么错误吗?
  • 如果没有配置方法响应,会不会报错?
  • 我不确定。你检查过吗?也许默认情况下它会被设置?
  • "why-did-aws-have-to-crash-today" :-)
  • 如果我的回答有帮助,我们将不胜感激。

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


【解决方案1】:

首先应该是:

IntegrationHttpMethod: POST

来自docs

或 Lambda 集成,您必须使用 POST 的 HTTP 方法进行集成请求,

其次,如果要显式添加MethodResponses,那么应该是:

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

【讨论】:

  • 又何必是IntegrationHttpMethod: POST……
  • @dataviews 我更新了答案。
  • 看来我遇到了另一个问题。奇怪的是,当我使用 CF 时,我无法在方法响应下显示 HTTP 状态:代理消息,但我的 500 问题与 APIG 无权调用代理服务 (lambda) 有关。如果您从控制台设置它,系统会提示您授予它权限,而在 CF 中您没有。而且我有 IntegrationHttpMethod: 设置为 ANY 并且它可以工作,但是在看到此文档后我将更新为 POST,其中 HttpMethod 仍将保持为 ANY
  • 我还要指出,只要您的代理 (lambda) 处理响应状态/消息,看来您不需要 MethodResponses。至少,我现在没有使用这个。我相信我在某个地方的文档中看到了这一点,只要您使用 lambda 的代理
  • @dataviews 这是我对MethodResponses的最初评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-04
  • 2020-10-19
  • 2020-06-28
  • 1970-01-01
  • 2013-10-25
相关资源
最近更新 更多