Skip to content

Commit

Permalink
Java V2 Add Java sagemaker workflow (#5193)
Browse files Browse the repository at this point in the history
* add Java Sagemaker workflow.
  • Loading branch information
scmacdon authored Aug 9, 2023
1 parent eec49b2 commit bf9e8e6
Show file tree
Hide file tree
Showing 14 changed files with 2,041 additions and 58 deletions.
54 changes: 54 additions & 0 deletions .doc_gen/metadata/sagemaker_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ sagemaker_Hello:
synopsis: get started using &SM;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/sagemaker
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.list_books.main
.NET:
versions:
- sdk_version: 3
Expand All @@ -22,6 +31,15 @@ sagemaker_CreatePipeline:
synopsis: create or update a pipeline in &SM;.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/usecases/workflow_sagemaker_pipes
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.create_pipeline.main
.NET:
versions:
- sdk_version: 3
Expand All @@ -39,6 +57,15 @@ sagemaker_ExecutePipeline:
synopsis: start a pipeline execution in &SM;.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/usecases/workflow_sagemaker_pipes
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.execute_pipeline.main
.NET:
versions:
- sdk_version: 3
Expand All @@ -56,6 +83,15 @@ sagemaker_DeletePipeline:
synopsis: delete a pipeline in &SM;.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/usecases/workflow_sagemaker_pipes
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.delete_pipeline.main
.NET:
versions:
- sdk_version: 3
Expand All @@ -73,6 +109,15 @@ sagemaker_DescribePipelineExecution:
synopsis: describe a pipeline execution in &SM;.
category:
languages:
Java:
versions:
- sdk_version: 2
github: javav2/usecases/workflow_sagemaker_pipes
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.describe_pipeline_execution.main
.NET:
versions:
- sdk_version: 3
Expand Down Expand Up @@ -307,6 +352,15 @@ sagemaker_Scenario_Pipelines:
- Clean up resources.
category: Scenarios
languages:
Java:
versions:
- sdk_version: 2
github: javav2/usecases/workflow_sagemaker_pipes
sdkguide:
excerpts:
- description:
snippet_tags:
- sagemaker.java2.sc.main
.NET:
versions:
- sdk_version: 3
Expand Down
2 changes: 2 additions & 0 deletions .github/pre_validate/pre_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
'aws/dynamodb/model/BatchWriteItemRequest',
'aws/rds/model/DescribeDBInstancesRequest',
'aws/rds/model/DescribeDBSnapshotsRequest',
'role/AmazonSageMakerGeospatialFullAccess',
'VectorEnrichmentJobDataSourceConfigInput',
}

def check_files(root, quiet):
Expand Down
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]
}
37 changes: 37 additions & 0 deletions javav2/usecases/workflow_sagemaker_lambda/Readme.md
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.
Loading

0 comments on commit bf9e8e6

Please sign in to comment.