Recommand · June 5, 2021 0

How to delete S3 object using cronjob

I have a python file in my EC2 which connects to S3 and deletes all versions of objects.


session = boto3.Session()
s3 = session.resource(service_name='s3')
bucket = s3.Bucket('mys3bucket-delete-me')

In my I call this python file


Make my file executable chmod +x and execute ./

This works fine and deletes all objects of my s3 bucket.

Issue is when I call this within crontab sudo crontab -e every minutes and it doesn’t execute
*/1 * * * * /home/ec2-user/

Please guide me what’s wrong?