Skip to content

Instantly share code, notes, and snippets.

@gmr
Created August 29, 2018 17:33
Show Gist options
  • Save gmr/1bd9310f1b28a0558912f63298df70ad to your computer and use it in GitHub Desktop.
Save gmr/1bd9310f1b28a0558912f63298df70ad to your computer and use it in GitHub Desktop.
Small Python CLI application for removing any object tags from all objects in a bucket
#!/usr/bin/env python3
import argparse
import logging
import sys
import boto3
LOGGER = logging.getLogger(__name__)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('bucket', nargs='?',
help='s3 bucket to remove object tags from')
args = parser.parse_args()
if not args.bucket:
sys.stderr.write(
'ERROR: Must specify the bucket to remove object tags from\n')
sys.exit(1)
client = boto3.client('s3')
paginator = client.get_paginator('list_objects_v2')
count = 0
for page in paginator.paginate(Bucket=args.bucket):
for item in page['Contents']:
client.delete_object_tagging(Bucket=args.bucket, Key=item['Key'])
LOGGER.info('Removed any tags from %s', item['Key'])
count += 0
LOGGER.info('Performed %i delete_object_tagging API calls', count)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment