Search code examples
amazon-web-servicesmultipart

Wrap JPEG image in a multipart header using AWS Lambda@Edge


I have been trying to read the AWS Lambda@Edge documentation, but I still cannot figure out if the following option is possible.

Assume I have an object (image.jpg, with size 32922 bytes) and I have setup AWS as static website. So I can retrieve:

$ GET http://example.com/image.jpg

I would like to be able to also expose:

$ GET http://example.com/image

Where the response body would be a multipart/related file (for example). Something like this :

--myboundary
Content-Type: image/jpeg;
Content-Length: 32922
MIME-Version: 1.0

<actual binary jpeg data from 'image.jpg'>
--myboundary

Is this something supported out of the box in the AWS Lambda@Edge API ? or should I use another solution to create such response ? In particular it seems that the response only deal with text or base64 (I would need binary in my case).


Solution

  • I finally was able to find complete documentation. I eventually stumble upon:

    which refers to:

    The above documentation specify the steps to handle binary data. Pay attention that you need to base64 encode the response from lambda to pass it to API Gateway.