Skip to content

Instantly share code, notes, and snippets.

@wrburgess
Created July 26, 2023 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrburgess/f03fe229bd2cbdc5e335a479d7992a48 to your computer and use it in GitHub Desktop.
Save wrburgess/f03fe229bd2cbdc5e335a479d7992a48 to your computer and use it in GitHub Desktop.
aws cli s3 delete all delete markers from bucket bash script
#!/bin/bash
export AWS_PAGER=""
bucket_name="bucket-name"
# List all versions in the bucket
versions=$(aws s3api list-object-versions --bucket $bucket_name --query 'DeleteMarkers')
# Loop through the list of delete markers and delete each one
for version in $(echo "$versions" | jq -r '.[] | @base64'); do
version_json=$(echo "$version" | base64 --decode)
version_id=$(echo "$version_json" | jq -r '.VersionId')
key=$(echo "$version_json" | jq -r '.Key')
# Delete the delete marker
aws s3api delete-object --bucket $bucket_name --key "$key" --version-id $version_id
# echo "Deleted delete marker for: $key (Version ID: $version_id)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment