Skip to content

Instantly share code, notes, and snippets.

@floehopper
Created November 24, 2017 14:54
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 floehopper/4234ebe26d08ad5e941eaaf7000354c5 to your computer and use it in GitHub Desktop.
Save floehopper/4234ebe26d08ad5e941eaaf7000354c5 to your computer and use it in GitHub Desktop.
aws s3api list-objects-v2 --bucket govuk-assets-production --query 'Contents[?length(@.Key) == `24`].[Key]' --output text > orphan-s3-object-keys.txt
cat orphan-s3-object-keys.txt | wc -l
# ensure the result is 1137
cat orphan-s3-object-keys.txt | xargs -I {} aws s3api delete-object --bucket govuk-assets-production --key {} --output text > deleted-s3-objects.txt
aws s3api delete-object --bucket govuk-assets-production --key 9883ea2d-995f-4418-9ca1-abf31b572fa4 --output text >> deleted-s3-objects.txt
aws s3api delete-object --bucket govuk-assets-production --key be8a0003-4b25-4047-8a5f-f7ddc3c52716 --output text >> deleted-s3-objects.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment