1

I've created a lambda to upload and download images to s3.

The problem I'm facing is that I am struggling with the proxy integration from the API Gateway.

After check the documentation and this question about Gateway and Lambda to Return Image I can either have the upload working or the download working but not both :(

If I add - */* in the binaryMediaTypes from apiGateway in my serverless.yml file as it was suggested in the linked stack over flow question I got the download to work but then my upload func brakes...(It returns 502)

If I don't add this */*, upload works but then I cannot do the download...

I've tried to do the upload from different ways such as adding the file in a form or in the body as a base64 string, both work without the */* but brakes when the */* is added...

I couldn't find another way to make the download to work in a way that I don't brake the upload part...

Any clues?

( obs1: I am setting the content-type to 'image/jpeg' in the download return obj )

(obs2: I know you can download image directly from s3 but I have some logic implemented on the lambda to decide which image should be served so I want to do this through the lambda)

Here is the part of the serverless.yml file regarding the gateway:

  • Two questions. 1. Are you returning binary or base64 data from the lambda? Are you returning a content-type header in your response? – K Mo Nov 28 '19 at 07:33
  • It is probable that something with your response format from both the upload and download is not quite right. You could check by looking to see if your upload actually gets into S3 when it returns a 502 error. If this is the case, please post your response formats from both functions. – K Mo Nov 28 '19 at 09:58

1 Answers1

0

Best way to upload and download image from s3 via lambda is pre-signed URL.

Use lambda to create pre-signed URL

Tuan Vo
  • 1,875
  • 10
  • 10