-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java V2 Add Java sagemaker workflow (#5193)
* add Java Sagemaker workflow.
- Loading branch information
Showing
14 changed files
with
2,041 additions
and
58 deletions.
There are no files selected for viewing
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
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
114 changes: 56 additions & 58 deletions
114
.../java/com/example/sage/ListNotebooks.java → ...java/com/example/sage/HelloSageMaker.java
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,58 +1,56 @@ | ||
//snippet-sourcedescription:[ListNotebooks.java demonstrates how to list notebooks.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-keyword:[Amazon SageMaker] | ||
|
||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.example.sage; | ||
|
||
//snippet-start:[sagemaker.java2.list_books.import] | ||
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.sagemaker.SageMakerClient; | ||
import software.amazon.awssdk.services.sagemaker.model.ListNotebookInstancesResponse; | ||
import software.amazon.awssdk.services.sagemaker.model.NotebookInstanceSummary; | ||
import software.amazon.awssdk.services.sagemaker.model.SageMakerException; | ||
import java.util.List; | ||
//snippet-end:[sagemaker.java2.list_books.import] | ||
|
||
/** | ||
* Before running this Java V2 code example, set up your development environment, including your credentials. | ||
* | ||
* For more information, see the following documentation topic: | ||
* | ||
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html | ||
*/ | ||
public class ListNotebooks { | ||
|
||
public static void main(String[] args) { | ||
|
||
Region region = Region.US_WEST_2; | ||
SageMakerClient sageMakerClient = SageMakerClient.builder() | ||
.region(region) | ||
.credentialsProvider(ProfileCredentialsProvider.create()) | ||
.build(); | ||
|
||
listBooks(sageMakerClient); | ||
sageMakerClient.close(); | ||
} | ||
|
||
//snippet-start:[sagemaker.java2.list_books.main] | ||
public static void listBooks(SageMakerClient sageMakerClient) { | ||
try { | ||
ListNotebookInstancesResponse notebookInstancesResponse = sageMakerClient.listNotebookInstances(); | ||
List<NotebookInstanceSummary> items = notebookInstancesResponse.notebookInstances(); | ||
for (NotebookInstanceSummary item: items) { | ||
System.out.println("The notebook name is: "+item.notebookInstanceName()); | ||
} | ||
|
||
} catch (SageMakerException e) { | ||
System.err.println(e.awsErrorDetails().errorMessage()); | ||
System.exit(1); | ||
} | ||
} | ||
//snippet-end:[sagemaker.java2.list_books.main] | ||
} | ||
//snippet-sourcedescription:[HelloSageMaker.java demonstrates how to list notebooks.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-keyword:[Amazon SageMaker] | ||
|
||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.example.sage; | ||
|
||
//snippet-start:[sagemaker.java2.list_books.import] | ||
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.sagemaker.SageMakerClient; | ||
import software.amazon.awssdk.services.sagemaker.model.ListNotebookInstancesResponse; | ||
import software.amazon.awssdk.services.sagemaker.model.NotebookInstanceSummary; | ||
import software.amazon.awssdk.services.sagemaker.model.SageMakerException; | ||
import java.util.List; | ||
//snippet-end:[sagemaker.java2.list_books.import] | ||
|
||
//snippet-start:[sagemaker.java2.list_books.main] | ||
/** | ||
* Before running this Java V2 code example, set up your development environment, including your credentials. | ||
* | ||
* For more information, see the following documentation topic: | ||
* | ||
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html | ||
*/ | ||
public class HelloSageMaker { | ||
public static void main(String[] args) { | ||
Region region = Region.US_WEST_2; | ||
SageMakerClient sageMakerClient = SageMakerClient.builder() | ||
.region(region) | ||
.credentialsProvider(ProfileCredentialsProvider.create()) | ||
.build(); | ||
|
||
listBooks(sageMakerClient); | ||
sageMakerClient.close(); | ||
} | ||
|
||
public static void listBooks(SageMakerClient sageMakerClient) { | ||
try { | ||
ListNotebookInstancesResponse notebookInstancesResponse = sageMakerClient.listNotebookInstances(); | ||
List<NotebookInstanceSummary> items = notebookInstancesResponse.notebookInstances(); | ||
for (NotebookInstanceSummary item: items) { | ||
System.out.println("The notebook name is: "+item.notebookInstanceName()); | ||
} | ||
|
||
} catch (SageMakerException e) { | ||
System.err.println(e.awsErrorDetails().errorMessage()); | ||
System.exit(1); | ||
} | ||
} | ||
//snippet-end:[sagemaker.java2.list_books.main] | ||
} |
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,37 @@ | ||
# Create the SageMaker geospatial Lambda function using the Lambda Java rumtime API | ||
|
||
This example demonstrates how to create a Lambda function for the Amazon SageMaker pipeline and geospatial job example. | ||
|
||
A [SageMaker pipeline](https://docs.aws.amazon.com/sagemaker/latest/dg/pipelines.html) is a series of | ||
interconnected steps that can be used to automate machine learning workflows. You can create and run pipelines from SageMaker Studio by using Python, but you can also do this by using AWS SDKs in other | ||
languages. Using the SDKs, you can create and run SageMaker pipelines and also monitor operations for them. | ||
|
||
You need to build this Lambda function in order to successfully complete the Java example. You can find the full example under **workflow_sagemaker_pipes**. | ||
|
||
### Prerequisites | ||
|
||
To use this tutorial, you need the following: | ||
|
||
+ An AWS account. | ||
+ A Java IDE. | ||
+ Java 1.8 JDK or later. | ||
+ Maven 3.6 or later. | ||
+ Set up your development environment. For more information, see [Get started with the SDK for Java](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup-basics.html). | ||
|
||
### Create a .jar file | ||
|
||
You can compile the project into a .jar file, which will serve as input for [Create and run a SageMaker geospatial pipeline using the SDK for Java V2](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/usecases/workflow_sagemaker_pipes). This can be achieved by using the following Maven command. | ||
|
||
mvn package | ||
|
||
The .jar file is located in the target folder. | ||
|
||
## Additional resources | ||
|
||
* [SageMaker Developer Guide](https://docs.aws.amazon.com/sagemaker/latest/dg/whatis.html) | ||
* [SageMaker API Reference](https://docs.aws.amazon.com/sagemaker/latest/APIReference/Welcome.html) | ||
* [Java Developer Guide](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html) | ||
|
||
--- | ||
|
||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
Oops, something went wrong.