Skip to content

Instantly share code, notes, and snippets.

@charsyam
Created March 17, 2021 06:00
Show Gist options
  • Save charsyam/378c21d1bdaa9efc74f507d2e8f4f646 to your computer and use it in GitHub Desktop.
Save charsyam/378c21d1bdaa9efc74f507d2e8f4f646 to your computer and use it in GitHub Desktop.
import boto3
import logging
logger = logging.getLogger('dag')
logger.setLevel(logging.INFO)
def get_url(bucket_name, obj):
return f"s3://{bucket}/{obj.key}"
def remove_conflict_metafiles(bucket_name, prefix):
filters = ["_committed_", "_started_"]
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
objs = []
for obj in bucket.objects.filter(Prefix=prefix):
for _filter in filters:
prefix_filter = prefix + _filter
if obj.key.startswith(prefix_filter):
objs.append({'Key': obj.key})
if len(objs) > 0:
s3client = boto3.client("s3")
resp = s3client.delete_objects(Bucket=bucket_name, Delete={'Objects': objs})
logger.info(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment