0

I'm using AWS SAM to deploy locally my Lambda function and test it.

I'm creating a function that receives a multipart/form-data body (includes a pdf file). When I do the request, lambda returns a 502 BAD GATEWAY message, but if I send only the text attributes or text files (markdown, text, xml, html) instead of binary files (pdf, images, etc.) It works. Here's my code.

template.yml

...
  PostRequest:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Handler: com.demo.handlers.request.PostRequest
      Runtime: java11
      Description: Post a Request
      MemorySize: 512
      Timeout: 100
      Events:
        HttpPost:
          Type: Api
          Properties:
            Path: /requests
            Method: post
            BinaryMediaTypes:
              - "multipart/form-data"
...

I tried adding application/pdf to the BinaryMediaTypes property but It still not working.

Is there a workaround to manage this?

1 Answers1

2

I know it's late, but I'm dropping what works for me in case someone land here and have the same issue.

...

Globals:
  Api:
    BinaryMediaTypes:
      - "*~1*"
Resources:
  PostRequest:
    Type: AWS::Serverless::Function
      Properties:

...
  • Wow, hours and hours trying to figure out this. Using SAM to test locally I was seen this error: ```UnicodeDecodeError while processing HTTP request: 'utf-8' codec can't decode byte 0xe2 in position 194: invalid continuation byte``` After reading a lot, this was the only thing that fixed. Thank you. – calbertts Sep 01 '22 at 16:35