Search code examples
file-uploadamazon-s3aws-lambdaaws-api-gateway

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


Solution

  • 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.