This simple script will look through a bucket to find all objects that match a LastModified
date and delete. This can be adjusted to delete objects before, after, or matching the date specified. Use at your own risk.
import boto3 from datetime import datetime, timezone s3 = boto3.client("s3") bucket = "INSERT_BUCKET_NAME" paginator = s3.get_paginator("list_objects_v2") pages = paginator.paginate(Bucket=bucket) date_check = datetime(2021, 11, 1) keys_to_delete = [] for page in pages: for object in page["Contents"]: if object["LastModified"] > date_check.replace(tzinfo=timezone.utc): keys_to_delete.append({"Key": object["Key"]}) s3.delete_objects(Bucket=bucket, Delete={"Objects": keys_to_delete})
Gist here.