Skip to content

Instantly share code, notes, and snippets.

@dmurawsky
Created May 22, 2020 17:41
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 dmurawsky/8732de4ac0984d6c7bb2a7824fd3a90e to your computer and use it in GitHub Desktop.
Save dmurawsky/8732de4ac0984d6c7bb2a7824fd3a90e to your computer and use it in GitHub Desktop.
AWS CLI delete all tags in a bucket
# Make sure you have aws installed: https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html
# Make sure you have jq installed: https://github.com/stedolan/jq/wiki/Installation
BUCKET=my-s3-bucket
PREFIX=path/to/objects
PROFILE=default
aws s3api list-objects --bucket $BUCKET --prefix $PREFIX --profile $PROFILE \ # List objects in bucket and prefix
| jq ".Contents" \ # Get the array of ojbects
| jq "map(\"aws s3api delete-object-tagging --profile ${PROFILE} --bucket ${BUCKET} --key \" + .Key)" \ # Create a delete-object-tagging command for each object
| jq -r '.[]' \ # Output one command per line
| sh # Pass the commands into shell to be run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment