1

AWS::Serverless::HttpApi定义了以下内容:

MyApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      CorsConfiguration:
        AllowOrigins:
          - http://localhost:3000
          - https://localhost:3000
          - https://my.site
      Domain:
        CertificateArn: !Ref MahCert
        DomainName: api.my.site
        EndpointConfiguration: REGIONAL
        Route53:
          # Very similar to one of the record sets in the R53 record set groups
          DistributionDomainName: !GetAtt CloudFrontCDN.DomainName
          HostedZoneId: !Ref MyHostedZone
          IpV6: true
      StageName: Prod
      DefinitionBody:
        openapi: "3.0.1"
        info:
          title: api.my.site
        paths:
          /steam/hours:
            get:
              responses:
                "200":
                  description: "200 response"
                  headers:
                    Access-Control-Allow-Origin:
                      schema:
                        type: "string"
                  content: { }
              x-amazon-apigateway-integration:
                type: "http"
                httpMethod: "GET"
                uri: "https://example.com"
                responses:
                  default:
                    statusCode: "200"
                    responseParameters:
                      method.response.header.Access-Control-Allow-Origin: "'*'"
                passthroughBehavior: "when_no_match"

      AccessLogSettings:
        DestinationArn: !GetAtt CloudWatchLogGroup.Arn
        Format: '{ "$context.requestId": { "error": { "message": "$context.error.message", "messageString": "$context.error.messageString", "responseType": "$context.error.responseType" }, "integrationError": { "message": "$context.integrationErrorMessage", "error": "$context.integration.error", "status": "$context.integration.status" }}}'

这个 OpenAPI 定义应该定义一个带有 HTTP 集成的路由,该路由将请求代理到https://example.com. 我实际上是从我手动构建的 REST API 中导出了这个 OpenAPI 规范。CloudFormation 没有关于缺少属性的任何问题。

当我尝试访问该路由时,我得到一个 404。原因是该路由实际上没有任何集成: 在此处输入图像描述

为什么 CloudFormation 不在这里应用 http 集成?

4

1 回答 1

1

AWS Gateway 上的HttpApi不支持HTTP自定义集成。它确实支持HTTP_PROXY集成。是文档。Rest API支持两者和HTTP集成HTTP_PROXY

要添加HTTP_PROXY集成,以下是模板在操作中的外观/steam/hours GET

paths:
  /steam/hours:
    get:
      x-amazon-apigateway-integration:
        type: "http_proxy"
        httpMethod: "GET"
        uri: "https://example.com"
        payloadFormatVersion: "1.0"
于 2021-08-13T13:20:42.640 回答