Abhishek Jain
Abhishek Jain

Reputation: 195

How to setup cloud-watch alarm for s3 bucket if no data is received in bucket for 5 or 10 minutes?

I have an s3 bucket where at every 3 min one tar file is getting uploaded. Now I want to set up alarm notification if s3 file does not receive any data for 5 min I should get notified by an email. Unfortunately I am unable to find any such metrics in cloud-watch s3. Please let me know if anyone has solution for this.

Upvotes: 2

Views: 4873

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 270104

Amazon CloudWatch has a NumberOfObjects metric for every Amazon S3 bucket.

However, I'm not sure how often it is updated. It certainly wouldn't have 5-minute resolution.

Plus, there is no Alarm that means "if this number has not changed".

If your bucket does not have many objects (eg < 1000), one approach would be:

  • Create an Amazon CloudWatch Events rule to trigger an AWS Lambda function
  • The Lambda function would call list_bucket() to retrieve a list of objects from the bucket, then sort by LastModified
  • If it has been more than x minutes since a new file, then trigger a notification

If the bucket has many objects, then:

  • Create an Amazon S3 Event to trigger an AWS Lambda function whenever an object is added to the bucket
    • The Lambda function should update a database (eg DynamoDB) with the current timestamp
  • Create an Amazon CloudWatch Events rule to trigger an AWS Lambda function
    • The Lambda function would retrieve the timestamp from the database and compare it to the current time
    • If it has been more than x minutes since a new file was added, then trigger a notification

Upvotes: 2

Related Questions