Home > Mobile >  Download binary (nosql db) through ApiGateway gives Execution failed due to configuration error: Una
Download binary (nosql db) through ApiGateway gives Execution failed due to configuration error: Una

Time:12-14

I have this CloudFormation method definition:

  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

When testing through ApiGateway UI, I'm getting

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

Seems that the binary data have been received from S3 correctly with application/octet-stream ContentType but not correctly pushed through api gateway. This configuration works fine with image/jpg and zip objects, but not with NoSQL db

When testing from Postman or Curl, Im getting 200 with no content

Can anyone help me with th configuration?

Thanks!

EDIT: Once I change ContentHandling: CONVERT_TO_BINARY to CONVERT_TO_TEXT, ApiGateway test UI seems working:

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

But when requesting from CURL, still getting 200 with empty body. On the contrary of the log I see in ApiGateway, CURL receives Content-Type:application/json no matter what Accept header I send to the server

CodePudding user response:

To be honest, I was relying on auto-deploy but in fact, auto-deploy did not deploy the stack at all :-( When deploying the API manually, it started working like a charm

  • Related