Skip to content

Commit

Permalink
Update AWS_helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
qualiaMachine authored Nov 6, 2024
1 parent a5ab5b1 commit 5f86d79
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/AWS_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ def calculate_s3_storage_cost(bucket_name):

return cost, total_size_gb

def list_S3_objects(bucket_name):
"""
Lists all objects in a specified S3 bucket.
Parameters:
bucket_name (str): The name of the S3 bucket.
Returns:
list: A list of object keys (paths) in the bucket, or an empty list if the bucket is empty.
"""
s3 = boto3.client('s3')
file_list = []

# Use paginator to list all objects in the bucket
paginator = s3.get_paginator('list_objects_v2')
for page in paginator.paginate(Bucket=bucket_name):
for obj in page.get('Contents', []):
file_list.append(obj['Key']) # Add each object's key to the list

# If the bucket is empty, return an empty list
return file_list

def get_instance_cost(instance_type, days=1):
"""
Fetches the cost for a specific instance type over a specified number of days.
Expand Down

0 comments on commit 5f86d79

Please sign in to comment.