如何从ApiGateway缓存资源获取内容编码

问题描述 投票:0回答:1

我们有一个返回gzip编码的端点。我们想缓存值,我们正在使用ApiGateway为我们做到这一点。资源方法定义如下,

GetManifestApiGatewayMethod: # very good
      Type: "AWS::ApiGateway::Method"
      Properties:
        AuthorizationType: "NONE"
        HttpMethod: "GET"
        ResourceId:
          Ref: ManifestConfigurationResource
        RestApiId:
          Ref: ApiGatewayRestApi
        RequestParameters:
          method.request.path.seasonCode: true
          method.request.path.facilityCode: true
          method.request.path.configurationCode: true
          method.request.querystring.policyCode: true
          method.request.header.PAC-Authorization: true
          method.request.header.PAC-Application-ID: true
          method.request.header.PAC-API-Key: true
          method.request.header.PAC-Channel-Code: true
          method.request.header.PAC-Organization-ID: true
          method.request.header.PAC-Developer-ID: true
          method.request.header.PAC-Request-ID: false
          method.request.header.Accept-Encoding: true
        MethodResponses:
          - StatusCode: 200
            # ResponseParameters:
            #   method.response.header.Content-Encoding: true
        Integration:
          IntegrationHttpMethod: GET
          Type: HTTP
          Uri: https://${self:provider.environment.PDI_HOST}/pdi/v1/manifest/{seasonCode}/{facilityCode}/{configurationCode}
          PassthroughBehavior: WHEN_NO_MATCH
          CacheKeyParameters:
            - method.request.path.seasonCode
            - method.request.path.facilityCode
            - method.request.path.configurationCode
            - method.request.querystring.policyCode
          IntegrationResponses:
            - StatusCode: 200
              SelectionPattern: '\d\d\d'
              # ResponseParameters:
              #   method.response.header.content-encoding: integration.response.body.headers.content-encoding
          RequestParameters:
            integration.request.path.seasonCode: method.request.path.seasonCode
            integration.request.path.facilityCode: method.request.path.facilityCode
            integration.request.path.configurationCode: method.request.path.configurationCode
            integration.request.querystring.policyCode: method.request.querystring.policyCode
            integration.request.header.Authorization: method.request.header.PAC-Authorization
            integration.request.header.PAC-Application-ID: method.request.header.PAC-Application-ID
            integration.request.header.PAC-API-Key: method.request.header.PAC-API-Key
            integration.request.header.PAC-Channel-Code: method.request.header.PAC-Channel-Code
            integration.request.header.PAC-Organization-ID: method.request.header.PAC-Organization-ID
            integration.request.header.PAC-Developer-ID: method.request.header.PAC-Developer-ID
            integration.request.header.PAC-Request-ID: method.request.header.PAC-Request-ID
            integration.request.header.Accept-Encoding: method.request.header.Accept-Encoding

http.get方法具有以下逻辑:

const encoding = response.headers["content-encoding"]; if (encoding && encoding.indexOf("gzip") >= 0) {...} // handle the gzip

“我尝试传递一些注释的代码,但是当使用这些响应映射时,我得到了internal server error
node.js amazon-cloudformation aws-api-gateway serverless
1个回答
0
投票
从代码模板的外观看,方法响应头看起来正确。

method.response.header.Content-Encoding: true

但是您的集成响应,ResponseParameters似乎是错误的。 

method.response.header.content-encoding: integration.response.body.headers.content-encoding

首先,属性

Key应该完全匹配,因此可能大写字母增加了问题。但是,您的Value似乎是真正的问题。按照AWS Documentation

将目标用作键,将源用作值:

目的地必须是 MethodResponse属性。

源必须是现有方法请求参数或静态 值。您必须将静态值括在单引号中,并将 根据在中指定的目标对这些值进行预编码 请求。

似乎您正在尝试将积分响应方法映射到值而不是

方法请求参数

© www.soinside.com 2019 - 2024. All rights reserved.