prefect_aws.s3
Tasks for interacting with AWS S3
Functions
get_s3_client
credentials: A dictionary of credentials to use for authentication with AWS.client_parameters: A dictionary of parameters to use for the boto3 client initialization.
- A boto3 S3 client.
adownload_from_bucket
bucket: Name of bucket to download object from. Required if a default value was not supplied when creating the task.key: Key of object to download. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization.
- A
bytesrepresentation of the downloaded object.
download_from_bucket
bucket: Name of bucket to download object from. Required if a default value was not supplied when creating the task.key: Key of object to download. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization.
- A
bytesrepresentation of the downloaded object.
aupload_to_bucket
data: Bytes representation of data to upload to S3.bucket: Name of bucket to upload data to. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization..key: Key of object to download. Defaults to a UUID string.
- The key of the uploaded object
upload_to_bucket
data: Bytes representation of data to upload to S3.bucket: Name of bucket to upload data to. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization..key: Key of object to download. Defaults to a UUID string.
- The key of the uploaded object
acopy_objects
S3Bucket.stream_from.
Added in prefect-aws==0.5.3.
Args:
source_path: The path to the object to copy. Can be a string orPath.target_path: The path to copy the object to. Can be a string orPath.source_bucket_name: The bucket to copy the object from.aws_credentials: Credentials to use for authentication with AWS.target_bucket_name: The bucket to copy the object to. If not provided, defaults tosource_bucket.**copy_kwargs: Additional keyword arguments to pass toS3Client.copy_object.
- The path that the object was copied to. Excludes the bucket name.
copy_objects
S3Bucket.stream_from.
Args:
source_path: The path to the object to copy. Can be a string orPath.target_path: The path to copy the object to. Can be a string orPath.source_bucket_name: The bucket to copy the object from.aws_credentials: Credentials to use for authentication with AWS.target_bucket_name: The bucket to copy the object to. If not provided, defaults tosource_bucket.**copy_kwargs: Additional keyword arguments to pass toS3Client.copy_object.
- The path that the object was copied to. Excludes the bucket name.
amove_objects
source_path: The path of the object to movetarget_path: The path to move the object tosource_bucket_name: The name of the bucket containing the source objectaws_credentials: Credentials to use for authentication with AWS.target_bucket_name: The bucket to copy the object to. If not provided, defaults tosource_bucket.
- The path that the object was moved to. Excludes the bucket name.
move_objects
source_path: The path of the object to movetarget_path: The path to move the object tosource_bucket_name: The name of the bucket containing the source objectaws_credentials: Credentials to use for authentication with AWS.target_bucket_name: The bucket to copy the object to. If not provided, defaults tosource_bucket.
- The path that the object was moved to. Excludes the bucket name.
alist_objects
bucket: Name of bucket to list items from. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization..prefix: Used to filter objects with keys starting with the specified prefix.delimiter: Character used to group keys of listed objects.page_size: Number of objects to return in each request to the AWS API.max_items: Maximum number of objects that to be returned by task.jmespath_query: Query used to filter objects based on object attributes refer to the boto3 docs for more information on how to construct queries.
- A list of dictionaries containing information about the objects retrieved. Refer to the boto3 docs for an example response.
list_objects
bucket: Name of bucket to list items from. Required if a default value was not supplied when creating the task.aws_credentials: Credentials to use for authentication with AWS.aws_client_parameters: Custom parameter for the boto3 client initialization..prefix: Used to filter objects with keys starting with the specified prefix.delimiter: Character used to group keys of listed objects.page_size: Number of objects to return in each request to the AWS API.max_items: Maximum number of objects that to be returned by task.jmespath_query: Query used to filter objects based on object attributes refer to the boto3 docs for more information on how to construct queries.
- A list of dictionaries containing information about the objects retrieved. Refer to the boto3 docs for an example response.
Classes
S3Bucket
Block used to store data using AWS S3 or S3-compatible object storage like MinIO.
Attributes:
bucket_name: Name of your bucket.credentials: A block containing your credentials to AWS or MinIO.bucket_folder: A default path to a folder within the S3 bucket to use for reading and writing objects.
adownload_folder_to_path
from_folder: The path to the folder to download from.to_folder: The path to download the folder to.**download_kwargs: Additional keyword arguments to pass toClient.download_file.
- The absolute path that the folder was downloaded to.
adownload_object_to_file_object
from_path: The path to the object to download from; this gets prefixed with the bucket_folder.to_file_object: The file-like object to download the object to.**download_kwargs: Additional keyword arguments to pass toClient.download_fileobj.
- The file-like object that the object was downloaded to.
adownload_object_to_path
from_path: The path to the object to download; this gets prefixed with the bucket_folder.to_path: The path to download the object to. If not provided, the object’s name will be used.**download_kwargs: Additional keyword arguments to pass toClient.download_file.
- The absolute path that the object was downloaded to.
aget_directory
from_path: Path in S3 bucket to download from. Defaults to the block’s configured basepath.local_path: Local path to download S3 contents to. Defaults to the current working directory.
alist_objects
folder: Folder to list objects from.delimiter: Character used to group keys of listed objects.page_size: Number of objects to return in each request to the AWS API.max_items: Maximum number of objects that to be returned by task.jmespath_query: Query used to filter objects based on object attributes refer to the boto3 docs for more information on how to construct queries.
- List of objects and their metadata in the bucket.
base_folder.
amove_object
self’s credentials
must have permission to read and delete the source object and write to the target
object. If the credentials do not have those permissions, this method will raise
an error. If the credentials have permission to read the source object but not
delete it, the object will be copied but not deleted.
Args:
from_path: The path of the object to move.to_path: The path to move the object to.to_bucket: The bucket to move to. Defaults to the current bucket.
- The path that the object was moved to. Excludes the bucket name.
aput_directory
local_path: Path to local directory to upload from.to_path: Path in S3 bucket to upload to. Defaults to block’s configured basepath.ignore_file: Path to file containing gitignore style expressions for filepaths to ignore.
aread_path
path: Entire path to (and including) the key.
astream_from
self’s credentials
allow for writes to the other bucket, try using S3Bucket.copy_object.
Added in version 0.5.3.
Args:
bucket: The bucket to stream from.from_path: The path of the object to stream.to_path: The path to stream the object to. Defaults to the object’s name.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the object was uploaded to.
aupload_from_file_object
from_file_object: The file-like object to upload from.to_path: The path to upload the object to.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the object was uploaded to.
aupload_from_folder
from_folder: The path to the folder to upload from.to_folder: The path to upload the folder to.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the folder was uploaded to.
aupload_from_path
from_path: The path to the file to upload from.to_path: The path to upload the file to.**upload_kwargs: Additional keyword arguments to pass toClient.upload.
- The path that the object was uploaded to.
awrite_path
dogs/small_dogs/havanese in an S3 Bucket:
basepath
- The base path of the S3 bucket.
basepath
copy_object
self’s credentials must have permission to read the source object and write
to the target object. If the credentials do not have those permissions, try
using S3Bucket.stream_from.
Args:
from_path: The path of the object to copy.to_path: The path to copy the object to.to_bucket: The bucket to copy to. Defaults to the current bucket.**copy_kwargs: Additional keyword arguments to pass toS3Client.copy_object.
- The path that the object was copied to. Excludes the bucket name.
download_folder_to_path
from_folder: The path to the folder to download from.to_folder: The path to download the folder to.**download_kwargs: Additional keyword arguments to pass toClient.download_file.
- The absolute path that the folder was downloaded to.
download_object_to_file_object
from_path: The path to the object to download from; this gets prefixed with the bucket_folder.to_file_object: The file-like object to download the object to.**download_kwargs: Additional keyword arguments to pass toClient.download_fileobj.
- The file-like object that the object was downloaded to.
download_object_to_path
from_path: The path to the object to download; this gets prefixed with the bucket_folder.to_path: The path to download the object to. If not provided, the object’s name will be used.**download_kwargs: Additional keyword arguments to pass toClient.download_file.
- The absolute path that the object was downloaded to.
get_directory
from_path: Path in S3 bucket to download from. Defaults to the block’s configured basepath.local_path: Local path to download S3 contents to. Defaults to the current working directory.
list_objects
folder: Folder to list objects from.delimiter: Character used to group keys of listed objects.page_size: Number of objects to return in each request to the AWS API.max_items: Maximum number of objects that to be returned by task.jmespath_query: Query used to filter objects based on object attributes refer to the boto3 docs for more information on how to construct queries.
- List of objects and their metadata in the bucket.
base_folder.
move_object
self’s credentials must
have permission to read and delete the source object and write to the target
object. If the credentials do not have those permissions, this method will raise
an error. If the credentials have permission to read the source object but not
delete it, the object will be copied but not deleted.
Args:
from_path: The path of the object to move.to_path: The path to move the object to.to_bucket: The bucket to move to. Defaults to the current bucket.
- The path that the object was moved to. Excludes the bucket name.
put_directory
local_path: Path to local directory to upload from.to_path: Path in S3 bucket to upload to. Defaults to block’s configured basepath.ignore_file: Path to file containing gitignore style expressions for filepaths to ignore.
read_path
path: Entire path to (and including) the key.
stream_from
self’s credentials
allow for writes to the other bucket, try using S3Bucket.copy_object.
Args:
bucket: The bucket to stream from.from_path: The path of the object to stream.to_path: The path to stream the object to. Defaults to the object’s name.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the object was uploaded to.
upload_from_file_object
from_file_object: The file-like object to upload from.to_path: The path to upload the object to.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the object was uploaded to.
upload_from_folder
from_folder: The path to the folder to upload from.to_folder: The path to upload the folder to.**upload_kwargs: Additional keyword arguments to pass toClient.upload_fileobj.
- The path that the folder was uploaded to.
upload_from_path
from_path: The path to the file to upload from.to_path: The path to upload the file to.**upload_kwargs: Additional keyword arguments to pass toClient.upload.
- The path that the object was uploaded to.
validate_credentials
write_path
dogs/small_dogs/havanese in an S3 Bucket: