-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated SageMaker examples to take a region arg; added doc comments. (#…
…524) * Updated SageMaker examples to take a region arg. * Updated SageMaker code examples based on feedback Co-authored-by: Russell Cohen <rcoh@amazon.com>
- Loading branch information
Showing
6 changed files
with
149 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 9 additions & 4 deletions
13
.../examples/sagemaker-helloworld/Cargo.toml → aws/sdk/examples/sagemaker/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
[package] | ||
name = "sagemaker-helloworld" | ||
name = "sagemaker-code-examples" | ||
version = "0.1.0" | ||
authors = ["Alistair McLean <mclean@amazon.com>"] | ||
authors = ["Alistair McLean <mclean@amazon.com>", "Doug Schwartz <dougsch@amazon.com>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
env_logger = "0.8.2" | ||
sagemaker = {package = "aws-sdk-sagemaker", path = "../../build/aws-sdk/sagemaker"} | ||
aws-types = { path = "../../build/aws-sdk/aws-types" } | ||
|
||
tokio = { version = "1", features = ["full"] } | ||
|
||
|
||
env_logger = "0.8.2" | ||
chrono = "0.4.19" | ||
structopt = { version = "0.3", default-features = false } | ||
tracing-subscriber = "0.2.18" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_types::region::ProvideRegion; | ||
|
||
use sagemaker::{Client, Config, Region}; | ||
|
||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
struct Opt { | ||
/// The AWS Region. Overrides environment variable AWS_DEFAULT_REGION. | ||
#[structopt(short, long)] | ||
default_region: Option<String>, | ||
|
||
/// Whether to display additional runtime information | ||
#[structopt(short, long)] | ||
verbose: bool, | ||
} | ||
|
||
/// Lists the your SageMaker jobs in an AWS Region. | ||
/// /// # Arguments | ||
/// | ||
/// * `[-d DEFAULT-REGION]` - The region in which the client is created. | ||
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable. | ||
/// If the environment variable is not set, defaults to **us-west-2**. | ||
/// * `[-v]` - Whether to display additional information.#[tokio::main] | ||
#[tokio::main] | ||
async fn main() -> Result<(), sagemaker::Error> { | ||
tracing_subscriber::fmt::init(); | ||
|
||
let Opt { | ||
default_region, | ||
verbose, | ||
} = Opt::from_args(); | ||
|
||
let region = default_region | ||
.as_ref() | ||
.map(|region| Region::new(region.clone())) | ||
.or_else(|| aws_types::region::default_provider().region()) | ||
.unwrap_or_else(|| Region::new("us-west-2")); | ||
|
||
if verbose { | ||
println!("SageMaker client version: {}", sagemaker::PKG_VERSION); | ||
println!("Region: {:?}", ®ion); | ||
println!(); | ||
} | ||
|
||
let conf = Config::builder().region(region).build(); | ||
let client = Client::from_conf(conf); | ||
let job_details = client.list_training_jobs().send().await?; | ||
|
||
println!("Job Name\tCreation DateTime\tDuration\tStatus"); | ||
for j in job_details.training_job_summaries.unwrap_or_default() { | ||
let name = j.training_job_name.as_deref().unwrap_or_default(); | ||
let creation_time = j.creation_time.unwrap().to_chrono(); | ||
let training_end_time = j.training_end_time.unwrap().to_chrono(); | ||
|
||
let status = j.training_job_status.unwrap(); | ||
let duration = training_end_time - creation_time; | ||
|
||
println!( | ||
"{}\t{}\t{}\t{:#?}", | ||
name, | ||
creation_time.format("%Y-%m-%d@%H:%M:%S"), | ||
duration.num_seconds(), | ||
status | ||
); | ||
} | ||
|
||
Ok(()) | ||
} |
66 changes: 66 additions & 0 deletions
66
aws/sdk/examples/sagemaker/src/bin/sagemaker-helloworld.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_types::region::ProvideRegion; | ||
|
||
use sagemaker::{Client, Config, Region}; | ||
|
||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
struct Opt { | ||
/// The region. Overrides environment variable AWS_DEFAULT_REGION. | ||
#[structopt(short, long)] | ||
default_region: Option<String>, | ||
|
||
/// Whether to display additional runtime information | ||
#[structopt(short, long)] | ||
verbose: bool, | ||
} | ||
|
||
/// Lists the name, status, and type of your SageMaker instances in an AWS Region. | ||
/// /// # Arguments | ||
/// | ||
/// * `[-d DEFAULT-REGION]` - The region in which the client is created. | ||
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable. | ||
/// If the environment variable is not set, defaults to **us-west-2**. | ||
/// * `[-v]` - Whether to display additional information. | ||
#[tokio::main] | ||
async fn main() -> Result<(), sagemaker::Error> { | ||
tracing_subscriber::fmt::init(); | ||
|
||
let Opt { | ||
default_region, | ||
verbose, | ||
} = Opt::from_args(); | ||
|
||
let region = default_region | ||
.as_ref() | ||
.map(|region| Region::new(region.clone())) | ||
.or_else(|| aws_types::region::default_provider().region()) | ||
.unwrap_or_else(|| Region::new("us-west-2")); | ||
|
||
if verbose { | ||
println!("SageMaker client version: {}", sagemaker::PKG_VERSION); | ||
println!("Region: {:?}", ®ion); | ||
} | ||
|
||
let conf = Config::builder().region(region).build(); | ||
let client = Client::from_conf(conf); | ||
let notebooks = client.list_notebook_instances().send().await?; | ||
|
||
for n in notebooks.notebook_instances.unwrap_or_default() { | ||
let n_instance_type = n.instance_type.unwrap(); | ||
let n_status = n.notebook_instance_status.unwrap(); | ||
let n_name = n.notebook_instance_name.as_deref().unwrap_or_default(); | ||
|
||
println!( | ||
"Notebook Name : {}, Notebook Status : {:#?}, Notebook Instance Type : {:#?}", | ||
n_name, n_status, n_instance_type | ||
); | ||
} | ||
|
||
Ok(()) | ||
} |