繁体   English   中英

通过 ApiGateway 下载二进制文件 (nosql db) 由于配置错误导致执行失败:无法对正文进行 base64 解码

[英]Download binary (nosql db) through ApiGateway gives Execution failed due to configuration error: Unable to base64 decode the body

我有这个 CloudFormation 方法定义:

  DownloadMethodGet:
    Type: AWS::ApiGateway::Method
    Properties:
      HttpMethod: GET
      ApiKeyRequired: true
      ResourceId: !Ref OfflineExtractorJobIdDownloadApiResource
      RestApiId: !Ref RestApi
      AuthorizationType: CUSTOM
      AuthorizerId: !Ref RestApiAuthorizer
      RequestParameters:
        method.request.path.jobid: true
        method.request.header.Accept: false
        method.request.header.Content-Type: false
        method.request.header.Range: false
      Integration:
        Type: AWS
        CacheKeyParameters:
          - 'method.request.path.jobid'
        RequestParameters:
          integration.request.path.jobid: 'method.request.path.jobid'
          integration.request.header.Accept: 'method.request.header.Accept'
          integration.request.header.Content-Type: 'method.request.header.Content-Type'
          integration.request.header.Range: 'method.request.header.Range'
        Uri: !Sub "${DownloadS3BucketArn}/export-{jobid}.db"
        Credentials: !Ref DownloadS3RoleName
        IntegrationHttpMethod: GET
        PassthroughBehavior: WHEN_NO_MATCH
        IntegrationResponses:
          - StatusCode: 200
            ContentHandling: CONVERT_TO_BINARY
            ResponseParameters:
              method.response.header.Content-Type: "integration.response.header.Content-Type"
              method.response.header.Content-Range: "integration.response.header.Content-Range"
            ResponseTemplates:
              application/json: ''
      MethodResponses:
        - StatusCode: 200
          ResponseModels:
            application/json: "Empty"
          ResponseParameters:
            method.response.header.Content-Type: true
            method.response.header.Content-Range: false

通过 ApiGateway UI 进行测试时,我得到

Sun Dec 11 06:24:35 UTC 2022 : Endpoint request body after transformations: 
Sun Dec 11 06:24:35 UTC 2022 : Sending request to https://s3-external-1.amazonaws.com/the-bucket/export-the-nosql-file.db
Sun Dec 11 06:24:35 UTC 2022 : Received response. Status: 200, Integration latency: 279 ms
Sun Dec 11 06:24:35 UTC 2022 : Endpoint response headers: {x-amz-id-2=BDwDmSffhPUoXGUB/VxQxZ5XVGufOcxa5an7gmwK9O2zXJROFOGHh/H0BRYPAabt6pVPR9EMubg=, x-amz-request-id=JNQ0Q84HENXZJTPH, Date=Sun, 11 Dec 2022 06:24:36 GMT, Last-Modified=Wed, 13 Jul 2022 08:57:15 GMT, ETag="6f7f45c10069472887d4306164fc84cd", Accept-Ranges=bytes, Content-Type=application/octet-stream, Server=AmazonS3, Content-Length=7102464}
Sun Dec 11 06:24:36 UTC 2022 : Endpoint response body before transformations: SQLite format 3@  (�Y [TRUNCATED]
Sun Dec 11 06:24:36 UTC 2022 : Execution failed due to configuration error: Unable to base64 decode the body.
Sun Dec 11 06:24:36 UTC 2022 : Method completed with status: 500

似乎已使用application/octet-stream ContentType 从 S3 正确接收二进制数据,但未通过 api 网关正确推送。 此配置适用于 image/jpg 和 zip 对象,但不适用于 NoSQL db

从 Postman 或 Curl 进行测试时,我得到 200 没有内容

谁能帮我配置一下?

谢谢!

编辑:一旦我将 ContentHandling: CONVERT_TO_BINARY 更改为 CONVERT_TO_TEXT,ApiGateway 测试 UI 似乎可以正常工作:

Execution log for request xxx
Sun Dec 11 09:47:02 UTC 2022 : Starting execution for request: xxx
Sun Dec 11 09:47:02 UTC 2022 : HTTP Method: GET, Resource Path: /offline-extractor/jobs2/the-file/download
Sun Dec 11 09:47:02 UTC 2022 : Method request path: {jobid=0014aa18-d3f7-4508-a5df-63fda8573dfc}
Sun Dec 11 09:47:02 UTC 2022 : Method request query string: {}
Sun Dec 11 09:47:02 UTC 2022 : Method request headers: {}
Sun Dec 11 09:47:02 UTC 2022 : Method request body before transformations: 
Sun Dec 11 09:47:02 UTC 2022 : Endpoint request URI: https://s3-external-1.amazonaws.com/acuttera-offline-extractor-prod/export-the-file.db
Sun Dec 11 09:47:02 UTC 2022 : Endpoint request headers: {Authorization=*****************************************************************************************************************************************************************************************************************************************************************************13e589, X-Amz-Date=20221211T094702Z, x-amzn-apigateway-api-id=xxx, Accept=application/json, User-Agent=AmazonAPIGateway_hoypjdvhx7, X-Amz-Security-Token=IQ [TRUNCATED]
Sun Dec 11 09:47:02 UTC 2022 : Endpoint request body after transformations: 
Sun Dec 11 09:47:02 UTC 2022 : Sending request to https://s3-external-1.amazonaws.com/the-bucket/export-the-file.db
Sun Dec 11 09:47:02 UTC 2022 : Received response. Status: 200, Integration latency: 67 ms
Sun Dec 11 09:47:02 UTC 2022 : Endpoint response headers: {x-amz-id-2=xxx x-amz-request-id=xxx, Date=Sun, 11 Dec 2022 09:47:03 GMT, Last-Modified=Sun, 10 Jul 2022 11:43:24 GMT, ETag="xxx", Accept-Ranges=bytes, Content-Type=application/octet-stream, Server=AmazonS3, Content-Length=638976}
Sun Dec 11 09:47:02 UTC 2022 : Endpoint response body before transformations: SQLite format 3@  ��U [TRUNCATED]
Sun Dec 11 09:47:02 UTC 2022 : Method response body after transformations: SQLite format 3@  ��U    [TRUNCATED]
Sun Dec 11 09:47:02 UTC 2022 : Method response headers: {X-Amzn-Trace-Id=Root=1-xxx, Content-Type=application/octet-stream}
Sun Dec 11 09:47:02 UTC 2022 : Successfully completed execution
Sun Dec 11 09:47:02 UTC 2022 : Method completed with status: 200

但是当从 CURL 请求时,仍然得到 200 的空体。 与我在 ApiGateway 中看到的日志相反,无论我向服务器发送什么 Accept 标头,CURL 都会收到 Content-Type:application/json

老实说,我依赖于自动部署,但实际上,自动部署根本没有部署堆栈:-( 手动部署 API 时,它开始工作得很好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM