Skip to content

Commit

Permalink
[ETL-670] Update code to paginate over all results (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble authored Jul 16, 2024
1 parent 170decb commit bedc391
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/scripts/manage_artifacts/clean_for_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ def delete_objects(bucket_prefix: str, bucket: str) -> None:
print(f"Cleaning bucket: {bucket} with prefix: {bucket_prefix}")

s3_client = boto3.client("s3")
response = s3_client.list_objects_v2(Bucket=bucket, Prefix=bucket_prefix)

# Check if objects are found
if "Contents" in response:
for obj in response["Contents"]:
object_key = obj["Key"]
paginator = s3_client.get_paginator("list_objects_v2")

# Skip the owner.txt file so it does not need to be re-created
if object_key.endswith("owner.txt"):
continue
for page in paginator.paginate(Bucket=bucket, Prefix=bucket_prefix):
# Check if objects are found
if "Contents" in page:
for obj in page["Contents"]:
object_key = obj["Key"]

s3_client.delete_object(Bucket=bucket, Key=object_key)
# Skip the owner.txt file so it does not need to be re-created
if object_key.endswith("owner.txt"):
continue

s3_client.delete_object(Bucket=bucket, Key=object_key)


def main() -> None:
Expand Down

0 comments on commit bedc391

Please sign in to comment.