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.
-
sagemaker.s3.
s3_path_join
(*args)¶ Returns the arguments joined by a slash (“/”), similarly to
os.path.join()
(on Unix).If the first argument is “s3://”, then that is preserved.
- Parameters
*args – The strings to join with a slash.
- Returns
The joined string.
- Return type
-
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, sagemaker_session=None)¶ Static method that uploads a given file or directory to S3.
- Parameters
local_path (str) – Path (absolute or relative) of local file or directory to upload.
desired_s3_uri (str) – The desired S3 location to upload to. It is the prefix to which the local filename will be added.
kms_key (str) – The KMS key to use to encrypt the files.
sagemaker_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, sagemaker_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.
sagemaker_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).
- 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, sagemaker_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.
sagemaker_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, sagemaker_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.
sagemaker_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 body of the file.
- Return type
-
static
list
(s3_uri, sagemaker_session=None)¶ Static method that lists the contents of an S3 uri.
- Parameters
s3_uri (str) – The S3 base uri to list objects in.
sagemaker_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 list of S3 URIs in the given S3 base uri.
- Return type
[str]
-
static