serverless/serverless

Binary and CORS support does not work togather

Aperta

#7243 aperta il 21 gen 2020

 (11 commenti) (0 reazioni) (0 assegnatari)JavaScript (5734 fork)batch import
bugcat/aws-event-api-gatewayenhancementhelp wanted

Metriche repository

Star
 (46.915 stelle)
Metriche merge PR
 (Merge medio 1g 15h) (34 PR mergiate in 30 g)

Descrizione

Bug Report

Description

  1. What did you do? Enabled binary media support and enabled cors support for each of the methods in serverless.yml. Setting cors true for the method creates OPTIONS request for the API GW endpoint and a MOCK end point is associated with the request. All of the stuff are created by the serverless framework deploy command without any manual configurations.
  2. What happened? API GW returns a 500 response with message "Internal server error" for OPTIONS requests when binary support is enabled and returns a proper 200 response otherwise when I remove "binaryMediaTypes" from serverless.yml and redeploy. When it returns a 500 response the below log entries can be seen for the API GW:
18:18:11 Method request body before transformations: [Binary Data]
18:18:11 Execution failed due to configuration error: Unable to transform response
  1. What should've happened? A 200 response should have been returned as with binary support disabled.
  2. What's the content of your serverless.yml file?
provider:
  apiGateway:
    binaryMediaTypes:
      - '*/*'

functions:
  someRandomFunction:
    handler: src/handlers/someHandler.getSomeData
    events:
      - http:
          path: getdata
          method: get
          cors: true

resources:
 Resources:
    GatewayResponseDefault4XX:
      Type: 'AWS::ApiGateway::GatewayResponse'
      Properties:
        ResponseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
        ResponseType: DEFAULT_4XX
        RestApiId:
          Ref: 'ApiGatewayRestApi'
  1. What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy) Deployment is a success and no errors are reported.

Similar or dependent issues: Similar discussions that I have found are linked below https://forums.aws.amazon.com/thread.jspa?threadID=256140

Guida contributor