【问题标题】:AWS::Serverless::HttpApi OpenAPI definition with http integrationAWS::Serverless::HttpApi OpenAPI 定义与 http 集成
【发布时间】:2021-10-08 07:29:43
【问题描述】:

我定义了以下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 集成?

【问题讨论】:

    标签: amazon-cloudformation aws-api-gateway openapi serverless-application-model aws-http-api


    【解决方案1】:

    AWS Gateway 上的 HttpApi 不支持 HTTP 自定义集成。它确实支持HTTP_PROXY 集成。 Here 是文档。 Rest APIs 支持 HTTPHTTP_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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      相关资源
      最近更新 更多