Search code examples
pythonamazon-web-servicesaws-lambdaamazon-sns

Alert if the contents of an S3 folder is not deleted by specific time


Can anyone please suggest me how to implement this specific use case? Every morning a python job from on premise server

  • clears the S3 folder contents and then
  • extracts files on premise from db and then
  • uploads the extracted files to the above S3 folder.

Sometimes, the python script which is scheduled to run through windows task scheduler job is just starting and finishing in seconds without doing any work. In order to send an alert notification when this happens, I am thinking of writing a lambda that is scheduled to run after like 5 minutes to see if the folder contents is deleted or not in the last few minutes to an SNS topic. Is this doable? Here the lambda trigger is not an S3 event but a scheduled event that can able to read S3 delete action.


Solution

  • Sure, you could do that.

    An easier method might be to add a step at the end of the Windows task that basically says "The job completed successfully". It could upload this file to S3.

    Then, the scheduled AWS Lambda function could simply check the LastModified date of that file. If it is older than one hour (or whatever), then send an alert via Amazon SNS.