I want to create a file watcher script that detects if the files in S3 folder have been refreshed or not. If yes, then it should execute a particular command in Unix. Please help me with this.
-
What have you tried so far? Where are you stuck? – Nico Haase Sep 03 '21 at 07:11
-
I have no idea how can I make that kind of script – Mihir Garg Sep 03 '21 at 07:28
2 Answers
What you need to do is to create a listener (a Lambda function) that will "listen" to the bucket changes. The available events can be found here.
So your code will be notified for every change you have asked to be notified about.
See here how to configure the bucket to fire the events.
Note that nothing will run on your Unix box. Your code will run on AWS and will execute your logic from AWS.

- 22,927
- 7
- 34
- 52
-
Thanks for your input. But i want a script in Unix to do all this stuff. – Mihir Garg Sep 03 '21 at 07:41
-
So you can do the following: Configure the bucket to send events to SQS. Write python code that will run on the unix box and listen to the SQS queue. The message will notify you about the changes. – balderman Sep 03 '21 at 08:14
-
Is there any way...I can do it entirely in Unix and don't use any additional AWS infra. – Mihir Garg Sep 03 '21 at 08:50
-
1
I create a python script that uses boto3 to get the object details. Then I extracted the timestamp from the object details and then I compare it with the previous timestamp or with my current timestamp. By this, I can know if the files are modified or not. If the file is modified I fire simple command to os which triggers the rest of the python code. To automate the process I created a cron job

- 29
- 3
-
Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 06 '21 at 07:09