Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive a response from AWS S3 triggered lambda function?

I currently have a setup where my mobile front-end performs an AWS s3 upload of an image. The s3 upload triggers a AWS lambda function that starts a AWS step-function (state-machine) which performs various jobs and actions.

I am looking for the best (and most time-efficient) way to get the output at the end of the step-function back to the mobile devise.

One way is to monitor the executionARN of the state machine and, when it is completed, fetch the data. This seems to be the case with awslabs lambda-refarch-imagerecognition implementation here. However, my front-end is on mobile and I would rather not have to send and receive many request to check if the state-machine is finished.

Another possible solution is to refactor the process so that the s3 upload is a stand-alone event and, once it has been successful, make an API request to an AWS API-gateway that triggers the step-function. The API POST request will then return the response. The problem here is that the app must wait for the s3 response to proceed with starting the state-machine.

Is there a a better way to perform this sequence and receive a response. Ideally, the s3 upload would return the full response from the state-machine. This way there one request (image-upload) and one response.

like image 608
robsalzwedel Avatar asked Nov 08 '22 19:11

robsalzwedel


1 Answers

I would use Amazon SNS -> push notifications. You say you want to avoid making "many requests" (and waiting for responses - or polling).

Amazon SNS allows you to publish to a specific topic.

Anything which is "subscribed" to the topic, will (receive a notification / message), whenever one (a stateless update) is published to the topic.

AWS SNS

The "mobile front-end" (device - you mention) "would receive the message" / receive push notifications from the SNS endpoint / topic.

This could be triggered when the "state machine" completes, allowing the mobile device to "get a timely update" via a push notification.

This would avoid polling for a response.

like image 136
chocksaway Avatar answered Dec 31 '22 01:12

chocksaway