AWS Class Documentation#

The AWS class provides methods to interact with Amazon Web Services (AWS) S3, facilitating the uploading and downloading of files.

class AWS(aws_access_key_id, aws_secret_access_key, region_name)#

Initializes the AWS S3 client with the necessary AWS credentials and region.

Parameters:
  • aws_access_key_id (str) – Your AWS access key ID.

  • aws_secret_access_key (str) – Your AWS secret access key.

  • region_name (str) – The AWS region to connect to.

upload(file_path, bucket_name, object_name)#

Uploads a file to AWS S3.

Parameters:
  • file_path (str) – The path to the file to upload.

  • bucket_name (str) – The name of the S3 bucket.

  • object_name (str) – The object name in S3.

Example:

aws_client = AWS('your-access-key-id', 'your-secret-access-key', 'us-east-1')
aws_client.upload_data('/local/path/to/file.txt', 'my-s3-bucket', 'path/in/bucket/file.txt')
download(bucket_name, object_name, file_path)#

Downloads a file from AWS S3.

Parameters:
  • bucket_name (str) – The name of the S3 bucket.

  • object_name (str) – The object name in S3.

  • file_path (str) – The local path to save the downloaded file.

Example:

aws_client = AWS('your-access-key-id', 'your-secret-access-key', 'us-east-1')
aws_client.download_data('my-s3-bucket', 'path/in/bucket/file.txt', '/local/path/to/save/file.txt')

S3 Cloud Storage

class unicloud.aws.S3(aws_access_key_id: str, aws_secret_access_key: str, region_name: str | None = None)#

Bases: CloudStorageFactory

S3 Cloud Storage

property client#

client.

create_client()#

Creates and returns an AWS S3 client instance.

initializing the AWS S3 client, passing credentials directly is one option. Another approach is to use AWS IAM roles for EC2 instances or to configure the AWS CLI with aws configure, which sets up the credentials file used by boto3. This can be a more secure and manageable way to handle credentials, especially in production environments.

Initialize the S3 client with AWS credentials and region.

download(bucket_path: str, file_path: str)#

Download a file from S3.

Parameters#

bucket_path: [str]

The bucket_path in the format “bucket_name/object_name”.

file_path: [str]

The path to save the downloaded file.

upload(path: str, bucket_path: str)#

Upload a file to S3.

Parameters#

path: [str]

The path to the file to upload.

bucket_path: [str]

The bucket_path in the format “bucket_name/object_name”.