Shizam
Shizam

Reputation: 9672

Uploading a file to Amazon S3, update a database and return a response

I see how to upload to Amazon S3 (from the client) and I see how to make requests to update a dynamoDB (from the client) but how do I upload a file to S3 such that I get a response back with "business logic" information?

For instance, I want to upload a photo to a uploadPhoto endpoint that will return to me the photoID of the photo in my dynamoDB model.

Yes I can upload a file to S3 and have it 'notify' Lambda but then its too late, S3 has already returned a response, Lambda can't send another response back to the client.

Its clear I shouldn't upload a file to Lambda.

So there is the API Gateway, its not clear that its a 'good idea' to upload files to API Gateway...

Upvotes: 0

Views: 1073

Answers (1)

Ryan
Ryan

Reputation: 5973

We just went through a similar scenario and unfortunately I think it comes down to 2 choices:

  1. Use multiple requests - Client calls lambda to get presigned url, client uploads file directly to s3, then client calls back to lambda, lets it know the file has been uploaded and gets a response with all the business logic

  2. One request - Create a service(likely on ec2) that sits in front of s3, so your client uploads directly to your service, your service then uploads to s3, does the business logic, and then sends the response back to the client. Definitely less work on the client but you get charged for twice as much bandwidth because you are uploading it twice.

We implemented #1 and it wasn't too hard. In our case the client is an Angular app so to the user it looks like one request but behind the scenes the app is making several calls.

Upvotes: 2

Related Questions