S3 Utilities¶
This module contains Enums and helper methods related to S3.
-
sagemaker.s3.
parse_s3_url
(url)¶ Returns an (s3 bucket, key name/prefix) tuple from a url with an s3 scheme. :param url: :type url: str
Returns: - A tuple containing:
- str: S3 bucket name str: S3 key
Return type: tuple
-
class
sagemaker.s3.
S3Uploader
¶ Bases:
object
Contains static methods for uploading directories or files to S3.
-
static
upload
(local_path, desired_s3_uri, kms_key=None, session=None)¶ Static method that uploads a given file or directory to S3.
Parameters: - local_path (str) – A local path to a file or directory.
- desired_s3_uri (str) – The desired S3 uri to upload to.
- kms_key (str) – The KMS key to use to encrypt the files.
- session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one using the default AWS configuration chain.
Returns: The S3 uri of the uploaded file(s).
-
static
upload_string_as_file_body
(body, desired_s3_uri=None, kms_key=None, session=None)¶ Static method that uploads a given file or directory to S3.
Parameters: - body (str) – String representing the body of the file.
- desired_s3_uri (str) – The desired S3 uri to upload to.
- kms_key (str) – The KMS key to use to encrypt the files.
- session (sagemaker.session.Session) – AWS session to use. Automatically generates one if not provided.
Returns: The S3 uri of the uploaded file(s).
Return type:
-
static
-
class
sagemaker.s3.
S3Downloader
¶ Bases:
object
Contains static methods for downloading directories or files from S3.
-
static
download
(s3_uri, local_path, kms_key=None, session=None)¶ Static method that downloads a given S3 uri to the local machine.
Parameters: - s3_uri (str) – An S3 uri to download from.
- local_path (str) – A local path to download the file(s) to.
- kms_key (str) – The KMS key to use to decrypt the files.
- session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, the estimator creates one using the default AWS configuration chain.
-
static
read_file
(s3_uri, session=None)¶ Static method that returns the contents of an s3 uri file body as a string.
Parameters: - s3_uri (str) – An S3 uri that refers to a single file.
- session (sagemaker.session.Session) – AWS session to use. Automatically generates one if not provided.
Returns: The body of the file.
Return type:
-
static
list
(s3_uri, session=None)¶ Static method that lists the contents of an S3 uri.
Parameters: - s3_uri (str) – The S3 base uri to list objects in.
- session (sagemaker.session.Session) – AWS session to use. Automatically generates one if not provided.
Returns: The list of S3 URIs in the given S3 base uri.
Return type: [str]
-
static