Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading an image through Amazon API gateway and lambda

I have a REST API with API gateway and Lambda. I wan't to create an endpoint for uploading a profile picture, that passes the file to a Lambda function, where it is been resized, registers it to the database and returning the url path of the new image.

Is there any way to do so with those services? Couldn't find anything online (the only suggestion I found is uploading directly to S3, which requires IAM permissions, and having an event triggering a Lambda function that resizing the picture).

Thanks

UPDATE

AWS updated APIGATEWAY and know you can send binaries through an endpoint
Thanks to @blue and @Manzo for commenting it

like image 661
Yonatan Avatar asked May 07 '16 15:05

Yonatan


2 Answers

Uploading a file directly to S3 doesn't necessarily require IAM permissions. You would create an API endpoint that returns a pre-signed S3 URL, which could then be used to upload the file directly to S3. The Lambda function behind the API endpoint would be the only thing that needed the correct IAM permissions for the S3 bucket.

like image 113
Mark B Avatar answered Nov 11 '22 00:11

Mark B


Since API Gateway and Lambda don't support natively currently, you can pass the file to a picture in based64 encoded to API Gateway then pass to Lambda function. Your Lambda function can based64 decoded, then resized, registers it to the database and returning the url path of the new image.

like image 31
Ka Hou Ieong Avatar answered Nov 11 '22 01:11

Ka Hou Ieong