- Newest
- Most votes
- Most comments
Hi,
For uploading image to a Lambda function, you can use API Gateway to expose the Lambda at an endpoint, and then make a POST request with the Content-Type header as multipart/form-data . Then from the Lambda function, you can store the image into S3 and invoke another API call.
You can follow along this blog [2] for reference.
** UPDATE **
To handle the multi-part upload in the Lambda, make sure to configure API Gateway Mapping Template [3]:
In the Integration Request section of your API Gateway POST method, select Mapping Templates. Add a new mapping template for multipart/form-data content type. This template should transform the incoming request body into a format that your Lambda function understands.
Then, in Lambda, use the below code:
imageBody = base64.b64decode(event['body-json'])
A similar blog post [4] explains the way to handle form-multipart. (Japanese content, use translator if needed)
References:
[1] https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html
[2] https://aws.amazon.com/blogs/compute/uploading-to-amazon-s3-directly-from-a-web-or-mobile-application/
[3] https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
[4] https://qiita.com/tetsu0831/items/220ba032116dc94063b3
Please let me know you have any other doubts regarding this.
Thanks,
Atul
Thanks,
Yes, we have made it that far. Just not sure how to handle the form data in the Python lambda.
Relevant content
- asked 3 years ago
- AWS OFFICIALUpdated 9 months ago

Thanks for the reply. I have updated the previous answer to assist you with your issue on handling the data in Lambda.