S3 Bucket module

S3_Bucket class for creation, deletion and listing S3 buckets. Also for adding files to specific Bucket. Logs are saved in logs/s3.log

class s3_bucket.S3_Bucket(access_key_id, secret_access_key, region)

Bases: object

add_file_model_S3_bucket(bucket_name, file_path, object_name)

Upload a file to S3 bucket.

Parameters:

bucket_namestr

Name of the S3 bucket where the file will be stored.

file_pathstr

Path to the file to be uploaded.

object_namestr

Name (with file extension) of the object in S3.

Returns:

bool

True if file upload is successful, False otherwise.

create_S3_bucket(bucket_name, type='model')

Create an S3 bucket with the specified bucket name and type (model or dataset)

Parameters:

bucket_namestr

Name of the S3 bucket to create.

typestr

Type of bucket, either “model” or “dataset”. Defaults to “model”. If type is “model”, will save in the .env file as BUCKET_MODEL, otherwise, will save as BUCKET_DATASET

Returns:

bool

True if bucket creation is successful, False otherwise.

delete_S3_bucket(bucket_name)

Delete S3 bucket and all objects within it.

Parameters:

bucket_namestr

Name of the S3 bucket to delete.

Returns:

bool

True if bucket deletion is successful, False otherwise.

handle_arguments(args)

Handle commandline arguments for bucket actions and file uploads.

Parameters:

argsargparse.Namespace

Parsed commandline arguments.

list_S3_buckets()

List all S3 buckets in the AWS account.

Returns:

bool

True if listing is successful, False otherwise.