Amazon S3 Python delete

There are a handful of options available to AWS users if and when they want to delete objects in an S3 bucket. For the task I had, I took it as an opportunity to write something in Python using the boto3 libraries, and albeit very basic, it did the job.

There were literally thousands of objects to remove from a number of prefixes in the target bucket, and with versioning enabled I also had to make sure it deleted these as well.

import boto3
import sys
s3 = boto3.resource('s3')
bucket = s3.Bucket("simon-bucket")
prefix = str(sys.argv[1])