4

AWS lambda makes it possible to run code in response to events, such as the uploading of a file to s3. However, the lambda callback notifies the event invoker, and not the user who initiated the event.

Consider the following scenario:

  1. A user uploads a file to s3
  2. That file is processed
  3. User receives notification that the processing is complete

How would you do this with AWS lambda?

1 Answer 1

3

When uploading the file, add the email address or other identifier to the object as Object User-Defined Metadata.

When uploading an object, you can also assign metadata to the object. You provide this optional information as a name-value (key-value) pair when you send a PUT or POST request to create the object. When uploading objects using the REST API the optional user-defined metadata names must begin with "x-amz-meta-" to distinguish them from other HTTP headers. When you retrieve the object using the REST API, this prefix is returned. When uploading objects using the SOAP API, the prefix is not required. When you retrieve the object using the SOAP API, the prefix is removed, regardless of which API you used to upload the object.

When the Lambda function completes the file processing, it can read that same metadata, and send an appropriate notification to the user.

Sign up to request clarification or add additional context in comments.

5 Comments

To expand on this answer... Lambda has no knowledge of who uploaded the file. Lambda is simply passed information about the new object in Amazon S3. The metadata idea works well, but requires that it be supplied when the file is uploaded to S3. This could be done as part of the HTML form that uploads to S3. However, if they are uploading directly, you might have trouble enforcing this requirement.
Could we expand on how would you send the notification to the user? In the case where the s3 upload is initiated from a simple html form with a logged in user, how would you then notify the web page that your lambda function(s) has finished?
@Fergie any change that you managed to find a good solution to this problem? i.e. how is the webpage notified?
@BKSpurgeon No, I didn't, and I am still curious. If you are also wondering then the best practical thing you can to is to upvote the question :)
I think you would need to expose an endpoint to your back end from lambda, and would then need to notify your clients via something like server side events or web sockets

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.