Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Notified when upload is completed in Amazon S3 bucket

Is there a way by which I can get notified when a upload is completed in S3 Bucket? The requirement is that I need to provide link to users after uploading of a video is complete in the bucket. By default now I provide link after 30 minutes of start of video, whether video takes 5 minutes to upload or 40 minutes. So is there any way like any API that provides information that the upload has been completed?

like image 504
Asus gates Avatar asked Sep 04 '15 04:09

Asus gates


2 Answers

Notifications can be triggered in Amazon S3 when any of the following occur:

  • s3:ObjectCreated:*
  • s3:ObjectCreated:Put
  • s3:ObjectCreated:Post
  • s3:ObjectCreated:Copy
  • s3:ObjectCreated:CompleteMultipartUpload
  • s3:ObjectRemoved:*
  • s3:ObjectRemoved:Delete
  • s3:ObjectRemoved:DeleteMarkerCreated
  • s3:ReducedRedundancyLostObject

Notifications can be sent via three destinations:

  • Amazon Simple Notification Service (SNS), which in-turn can send notifications via email, HTTP/S endpoint, SMS, mobile push notification
  • Amazon Simple Queueing Service (SQS)
  • Amazon Lambda (not currently available in all regions)

See: Configuring Amazon S3 Event Notifications

The most appropriate choice depends on your programming preference and how your app is written:

  • Use SNS to push to an HTTP endpoint to trigger some code in your app
  • Write some code to periodically check an SQS queue
  • Write a Lambda function in Node.js or Java

Once triggered, your code would then need to identify who uploaded the video, retrieve their user details, then send them an email notification. This would be easiest if you control the key (filename) of the object being uploaded, since this will assist in determining the user to notify.

like image 94
John Rotenstein Avatar answered Sep 28 '22 21:09

John Rotenstein


You can use Amazon Lambda to post a message to Amazon SNS (or notify you any other way) when a file is uploaded to S3.

  1. Setup an S3 trigger to your Lambda function. See this tutorial: http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser.html

  2. Inside your Lambda function, send out your notification. You can use SNS, SES, SQS, etc.

like image 41
Matt Houser Avatar answered Sep 28 '22 20:09

Matt Houser