Amazon 使用SDK适用于 Java 2.x 的个性化示例 - Amazon SDK for Java 2.x
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon 使用SDK适用于 Java 2.x 的个性化示例

以下代码示例向您展示了如何使用 Amazon SDK for Java 2.x 与 Amazon Personalize 配合使用来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 CreateBatchInferenceJob

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createPersonalizeBatchInferenceJob(PersonalizeClient personalizeClient, String solutionVersionArn, String jobName, String s3InputDataSourcePath, String s3DataDestinationPath, String roleArn, String explorationWeight, String explorationItemAgeCutOff) { long waitInMilliseconds = 60 * 1000; String status; String batchInferenceJobArn; try { // Set up data input and output parameters. S3DataConfig inputSource = S3DataConfig.builder() .path(s3InputDataSourcePath) .build(); S3DataConfig outputDestination = S3DataConfig.builder() .path(s3DataDestinationPath) .build(); BatchInferenceJobInput jobInput = BatchInferenceJobInput.builder() .s3DataSource(inputSource) .build(); BatchInferenceJobOutput jobOutputLocation = BatchInferenceJobOutput.builder() .s3DataDestination(outputDestination) .build(); // Optional code to build the User-Personalization specific item exploration // config. HashMap<String, String> explorationConfig = new HashMap<>(); explorationConfig.put("explorationWeight", explorationWeight); explorationConfig.put("explorationItemAgeCutOff", explorationItemAgeCutOff); BatchInferenceJobConfig jobConfig = BatchInferenceJobConfig.builder() .itemExplorationConfig(explorationConfig) .build(); // End optional User-Personalization recipe specific code. CreateBatchInferenceJobRequest createBatchInferenceJobRequest = CreateBatchInferenceJobRequest .builder() .solutionVersionArn(solutionVersionArn) .jobInput(jobInput) .jobOutput(jobOutputLocation) .jobName(jobName) .roleArn(roleArn) .batchInferenceJobConfig(jobConfig) // Optional .build(); batchInferenceJobArn = personalizeClient.createBatchInferenceJob(createBatchInferenceJobRequest) .batchInferenceJobArn(); DescribeBatchInferenceJobRequest describeBatchInferenceJobRequest = DescribeBatchInferenceJobRequest .builder() .batchInferenceJobArn(batchInferenceJobArn) .build(); long maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; while (Instant.now().getEpochSecond() < maxTime) { BatchInferenceJob batchInferenceJob = personalizeClient .describeBatchInferenceJob(describeBatchInferenceJobRequest) .batchInferenceJob(); status = batchInferenceJob.status(); System.out.println("Batch inference job status: " + status); if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return batchInferenceJobArn; } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }

以下代码示例演示如何使用 CreateCampaign

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void createPersonalCompaign(PersonalizeClient personalizeClient, String solutionVersionArn, String name) { try { CreateCampaignRequest createCampaignRequest = CreateCampaignRequest.builder() .minProvisionedTPS(1) .solutionVersionArn(solutionVersionArn) .name(name) .build(); CreateCampaignResponse campaignResponse = personalizeClient.createCampaign(createCampaignRequest); System.out.println("The campaign ARN is " + campaignResponse.campaignArn()); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateCampaign” 中的。

以下代码示例演示如何使用 CreateDataset

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createDataset(PersonalizeClient personalizeClient, String datasetName, String datasetGroupArn, String datasetType, String schemaArn) { try { CreateDatasetRequest request = CreateDatasetRequest.builder() .name(datasetName) .datasetGroupArn(datasetGroupArn) .datasetType(datasetType) .schemaArn(schemaArn) .build(); String datasetArn = personalizeClient.createDataset(request) .datasetArn(); System.out.println("Dataset " + datasetName + " created."); return datasetArn; } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateDataset” 中的。

以下代码示例演示如何使用 CreateDatasetExportJob

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createDatasetExportJob(PersonalizeClient personalizeClient, String jobName, String datasetArn, IngestionMode ingestionMode, String roleArn, String s3BucketPath, String kmsKeyArn) { long waitInMilliseconds = 30 * 1000; // 30 seconds String status = null; try { S3DataConfig exportS3DataConfig = S3DataConfig.builder().path(s3BucketPath).kmsKeyArn(kmsKeyArn).build(); DatasetExportJobOutput jobOutput = DatasetExportJobOutput.builder().s3DataDestination(exportS3DataConfig) .build(); CreateDatasetExportJobRequest createRequest = CreateDatasetExportJobRequest.builder() .jobName(jobName) .datasetArn(datasetArn) .ingestionMode(ingestionMode) .jobOutput(jobOutput) .roleArn(roleArn) .build(); String datasetExportJobArn = personalizeClient.createDatasetExportJob(createRequest).datasetExportJobArn(); DescribeDatasetExportJobRequest describeDatasetExportJobRequest = DescribeDatasetExportJobRequest.builder() .datasetExportJobArn(datasetExportJobArn) .build(); long maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; while (Instant.now().getEpochSecond() < maxTime) { DatasetExportJob datasetExportJob = personalizeClient .describeDatasetExportJob(describeDatasetExportJobRequest) .datasetExportJob(); status = datasetExportJob.status(); System.out.println("Export job status: " + status); if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) { return status; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }

以下代码示例演示如何使用 CreateDatasetGroup

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createDatasetGroup(PersonalizeClient personalizeClient, String datasetGroupName) { try { CreateDatasetGroupRequest createDatasetGroupRequest = CreateDatasetGroupRequest.builder() .name(datasetGroupName) .build(); return personalizeClient.createDatasetGroup(createDatasetGroupRequest).datasetGroupArn(); } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }

创建域数据集组。

public static String createDomainDatasetGroup(PersonalizeClient personalizeClient, String datasetGroupName, String domain) { try { CreateDatasetGroupRequest createDatasetGroupRequest = CreateDatasetGroupRequest.builder() .name(datasetGroupName) .domain(domain) .build(); return personalizeClient.createDatasetGroup(createDatasetGroupRequest).datasetGroupArn(); } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateDatasetGroup” 中的。

以下代码示例演示如何使用 CreateDatasetImportJob

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createPersonalizeDatasetImportJob(PersonalizeClient personalizeClient, String jobName, String datasetArn, String s3BucketPath, String roleArn) { long waitInMilliseconds = 60 * 1000; String status; String datasetImportJobArn; try { DataSource importDataSource = DataSource.builder() .dataLocation(s3BucketPath) .build(); CreateDatasetImportJobRequest createDatasetImportJobRequest = CreateDatasetImportJobRequest.builder() .datasetArn(datasetArn) .dataSource(importDataSource) .jobName(jobName) .roleArn(roleArn) .build(); datasetImportJobArn = personalizeClient.createDatasetImportJob(createDatasetImportJobRequest) .datasetImportJobArn(); DescribeDatasetImportJobRequest describeDatasetImportJobRequest = DescribeDatasetImportJobRequest.builder() .datasetImportJobArn(datasetImportJobArn) .build(); long maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; while (Instant.now().getEpochSecond() < maxTime) { DatasetImportJob datasetImportJob = personalizeClient .describeDatasetImportJob(describeDatasetImportJobRequest) .datasetImportJob(); status = datasetImportJob.status(); System.out.println("Dataset import job status: " + status); if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return datasetImportJobArn; } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); } return ""; }

以下代码示例演示如何使用 CreateEventTracker

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createEventTracker(PersonalizeClient personalizeClient, String eventTrackerName, String datasetGroupArn) { String eventTrackerId = ""; String eventTrackerArn; long maxTime = 3 * 60 * 60; // 3 hours long waitInMilliseconds = 20 * 1000; // 20 seconds String status; try { CreateEventTrackerRequest createEventTrackerRequest = CreateEventTrackerRequest.builder() .name(eventTrackerName) .datasetGroupArn(datasetGroupArn) .build(); CreateEventTrackerResponse createEventTrackerResponse = personalizeClient .createEventTracker(createEventTrackerRequest); eventTrackerArn = createEventTrackerResponse.eventTrackerArn(); eventTrackerId = createEventTrackerResponse.trackingId(); System.out.println("Event tracker ARN: " + eventTrackerArn); System.out.println("Event tracker ID: " + eventTrackerId); maxTime = Instant.now().getEpochSecond() + maxTime; DescribeEventTrackerRequest describeRequest = DescribeEventTrackerRequest.builder() .eventTrackerArn(eventTrackerArn) .build(); while (Instant.now().getEpochSecond() < maxTime) { status = personalizeClient.describeEventTracker(describeRequest).eventTracker().status(); System.out.println("EventTracker status: " + status); if (status.equals("ACTIVE") || status.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return eventTrackerId; } catch (PersonalizeException e) { System.out.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return eventTrackerId; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateEventTracker” 中的。

以下代码示例演示如何使用 CreateFilter

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createFilter(PersonalizeClient personalizeClient, String filterName, String datasetGroupArn, String filterExpression) { try { CreateFilterRequest request = CreateFilterRequest.builder() .name(filterName) .datasetGroupArn(datasetGroupArn) .filterExpression(filterExpression) .build(); return personalizeClient.createFilter(request).filterArn(); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateFilter” 中的。

以下代码示例演示如何使用 CreateRecommender

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createRecommender(PersonalizeClient personalizeClient, String name, String datasetGroupArn, String recipeArn) { long maxTime = 0; long waitInMilliseconds = 30 * 1000; // 30 seconds String recommenderStatus = ""; try { CreateRecommenderRequest createRecommenderRequest = CreateRecommenderRequest.builder() .datasetGroupArn(datasetGroupArn) .name(name) .recipeArn(recipeArn) .build(); CreateRecommenderResponse recommenderResponse = personalizeClient .createRecommender(createRecommenderRequest); String recommenderArn = recommenderResponse.recommenderArn(); System.out.println("The recommender ARN is " + recommenderArn); DescribeRecommenderRequest describeRecommenderRequest = DescribeRecommenderRequest.builder() .recommenderArn(recommenderArn) .build(); maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; while (Instant.now().getEpochSecond() < maxTime) { recommenderStatus = personalizeClient.describeRecommender(describeRecommenderRequest).recommender() .status(); System.out.println("Recommender status: " + recommenderStatus); if (recommenderStatus.equals("ACTIVE") || recommenderStatus.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return recommenderArn; } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateRecommender” 中的。

以下代码示例演示如何使用 CreateSchema

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createSchema(PersonalizeClient personalizeClient, String schemaName, String filePath) { String schema = null; try { schema = new String(Files.readAllBytes(Paths.get(filePath))); } catch (IOException e) { System.out.println(e.getMessage()); } try { CreateSchemaRequest createSchemaRequest = CreateSchemaRequest.builder() .name(schemaName) .schema(schema) .build(); String schemaArn = personalizeClient.createSchema(createSchemaRequest).schemaArn(); System.out.println("Schema arn: " + schemaArn); return schemaArn; } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }

使用域创建架构。

public static String createDomainSchema(PersonalizeClient personalizeClient, String schemaName, String domain, String filePath) { String schema = null; try { schema = new String(Files.readAllBytes(Paths.get(filePath))); } catch (IOException e) { System.out.println(e.getMessage()); } try { CreateSchemaRequest createSchemaRequest = CreateSchemaRequest.builder() .name(schemaName) .domain(domain) .schema(schema) .build(); String schemaArn = personalizeClient.createSchema(createSchemaRequest).schemaArn(); System.out.println("Schema arn: " + schemaArn); return schemaArn; } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateSchema” 中的。

以下代码示例演示如何使用 CreateSolution

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createPersonalizeSolution(PersonalizeClient personalizeClient, String datasetGroupArn, String solutionName, String recipeArn) { try { CreateSolutionRequest solutionRequest = CreateSolutionRequest.builder() .name(solutionName) .datasetGroupArn(datasetGroupArn) .recipeArn(recipeArn) .build(); CreateSolutionResponse solutionResponse = personalizeClient.createSolution(solutionRequest); return solutionResponse.solutionArn(); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateSolution” 中的。

以下代码示例演示如何使用 CreateSolutionVersion

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String createPersonalizeSolutionVersion(PersonalizeClient personalizeClient, String solutionArn) { long maxTime = 0; long waitInMilliseconds = 30 * 1000; // 30 seconds String solutionStatus = ""; String solutionVersionStatus = ""; String solutionVersionArn = ""; try { DescribeSolutionRequest describeSolutionRequest = DescribeSolutionRequest.builder() .solutionArn(solutionArn) .build(); maxTime = Instant.now().getEpochSecond() + 3 * 60 * 60; // Wait until solution is active. while (Instant.now().getEpochSecond() < maxTime) { solutionStatus = personalizeClient.describeSolution(describeSolutionRequest).solution().status(); System.out.println("Solution status: " + solutionStatus); if (solutionStatus.equals("ACTIVE") || solutionStatus.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } if (solutionStatus.equals("ACTIVE")) { CreateSolutionVersionRequest createSolutionVersionRequest = CreateSolutionVersionRequest.builder() .solutionArn(solutionArn) .build(); CreateSolutionVersionResponse createSolutionVersionResponse = personalizeClient .createSolutionVersion(createSolutionVersionRequest); solutionVersionArn = createSolutionVersionResponse.solutionVersionArn(); System.out.println("Solution version ARN: " + solutionVersionArn); DescribeSolutionVersionRequest describeSolutionVersionRequest = DescribeSolutionVersionRequest.builder() .solutionVersionArn(solutionVersionArn) .build(); while (Instant.now().getEpochSecond() < maxTime) { solutionVersionStatus = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest) .solutionVersion().status(); System.out.println("Solution version status: " + solutionVersionStatus); if (solutionVersionStatus.equals("ACTIVE") || solutionVersionStatus.equals("CREATE FAILED")) { break; } try { Thread.sleep(waitInMilliseconds); } catch (InterruptedException e) { System.out.println(e.getMessage()); } } return solutionVersionArn; } } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 CreateSolutionVersion” 中的。

以下代码示例演示如何使用 DeleteCampaign

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void deleteSpecificCampaign(PersonalizeClient personalizeClient, String campaignArn) { try { DeleteCampaignRequest campaignRequest = DeleteCampaignRequest.builder() .campaignArn(campaignArn) .build(); personalizeClient.deleteCampaign(campaignRequest); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DeleteCampaign” 中的。

以下代码示例演示如何使用 DeleteEventTracker

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void deleteEventTracker(PersonalizeClient personalizeClient, String eventTrackerArn) { try { DeleteEventTrackerRequest deleteEventTrackerRequest = DeleteEventTrackerRequest.builder() .eventTrackerArn(eventTrackerArn) .build(); int status = personalizeClient.deleteEventTracker(deleteEventTrackerRequest).sdkHttpResponse().statusCode(); System.out.println("Status code:" + status); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DeleteEventTracker” 中的。

以下代码示例演示如何使用 DeleteSolution

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void deleteGivenSolution(PersonalizeClient personalizeClient, String solutionArn) { try { DeleteSolutionRequest solutionRequest = DeleteSolutionRequest.builder() .solutionArn(solutionArn) .build(); personalizeClient.deleteSolution(solutionRequest); System.out.println("Done"); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DeleteSolution” 中的。

以下代码示例演示如何使用 DescribeCampaign

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void describeSpecificCampaign(PersonalizeClient personalizeClient, String campaignArn) { try { DescribeCampaignRequest campaignRequest = DescribeCampaignRequest.builder() .campaignArn(campaignArn) .build(); DescribeCampaignResponse campaignResponse = personalizeClient.describeCampaign(campaignRequest); Campaign myCampaign = campaignResponse.campaign(); System.out.println("The Campaign name is " + myCampaign.name()); System.out.println("The Campaign status is " + myCampaign.status()); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DescribeCampaign” 中的。

以下代码示例演示如何使用 DescribeRecipe

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void describeSpecificRecipe(PersonalizeClient personalizeClient, String recipeArn) { try { DescribeRecipeRequest recipeRequest = DescribeRecipeRequest.builder() .recipeArn(recipeArn) .build(); DescribeRecipeResponse recipeResponse = personalizeClient.describeRecipe(recipeRequest); System.out.println("The recipe name is " + recipeResponse.recipe().name()); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DescribeRecipe” 中的。

以下代码示例演示如何使用 DescribeSolution

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void describeSpecificSolution(PersonalizeClient personalizeClient, String solutionArn) { try { DescribeSolutionRequest solutionRequest = DescribeSolutionRequest.builder() .solutionArn(solutionArn) .build(); DescribeSolutionResponse response = personalizeClient.describeSolution(solutionRequest); System.out.println("The Solution name is " + response.solution().name()); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 DescribeSolution” 中的。

以下代码示例演示如何使用 ListCampaigns

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void listAllCampaigns(PersonalizeClient personalizeClient, String solutionArn) { try { ListCampaignsRequest campaignsRequest = ListCampaignsRequest.builder() .maxResults(10) .solutionArn(solutionArn) .build(); ListCampaignsResponse response = personalizeClient.listCampaigns(campaignsRequest); List<CampaignSummary> campaigns = response.campaigns(); for (CampaignSummary campaign : campaigns) { System.out.println("Campaign name is : " + campaign.name()); System.out.println("Campaign ARN is : " + campaign.campaignArn()); } } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 ListCampaigns” 中的。

以下代码示例演示如何使用 ListDatasetGroups

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void listDSGroups(PersonalizeClient personalizeClient) { try { ListDatasetGroupsRequest groupsRequest = ListDatasetGroupsRequest.builder() .maxResults(15) .build(); ListDatasetGroupsResponse groupsResponse = personalizeClient.listDatasetGroups(groupsRequest); List<DatasetGroupSummary> groups = groupsResponse.datasetGroups(); for (DatasetGroupSummary group : groups) { System.out.println("The DataSet name is : " + group.name()); System.out.println("The DataSet ARN is : " + group.datasetGroupArn()); } } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 ListDatasetGroups” 中的。

以下代码示例演示如何使用 ListRecipes

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void listAllRecipes(PersonalizeClient personalizeClient) { try { ListRecipesRequest recipesRequest = ListRecipesRequest.builder() .maxResults(15) .build(); ListRecipesResponse response = personalizeClient.listRecipes(recipesRequest); List<RecipeSummary> recipes = response.recipes(); for (RecipeSummary recipe : recipes) { System.out.println("The recipe ARN is: " + recipe.recipeArn()); System.out.println("The recipe name is: " + recipe.name()); } } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 ListRecipes” 中的。

以下代码示例演示如何使用 ListSolutions

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void listAllSolutions(PersonalizeClient personalizeClient, String datasetGroupArn) { try { ListSolutionsRequest solutionsRequest = ListSolutionsRequest.builder() .maxResults(10) .datasetGroupArn(datasetGroupArn) .build(); ListSolutionsResponse response = personalizeClient.listSolutions(solutionsRequest); List<SolutionSummary> solutions = response.solutions(); for (SolutionSummary solution : solutions) { System.out.println("The solution ARN is: " + solution.solutionArn()); System.out.println("The solution name is: " + solution.name()); } } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 ListSolutions” 中的。

以下代码示例演示如何使用 UpdateCampaign

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static String updateCampaign(PersonalizeClient personalizeClient, String campaignArn, String solutionVersionArn, Integer minProvisionedTPS) { try { // build the updateCampaignRequest UpdateCampaignRequest updateCampaignRequest = UpdateCampaignRequest.builder() .campaignArn(campaignArn) .solutionVersionArn(solutionVersionArn) .minProvisionedTPS(minProvisionedTPS) .build(); // update the campaign personalizeClient.updateCampaign(updateCampaignRequest); DescribeCampaignRequest campaignRequest = DescribeCampaignRequest.builder() .campaignArn(campaignArn) .build(); DescribeCampaignResponse campaignResponse = personalizeClient.describeCampaign(campaignRequest); Campaign updatedCampaign = campaignResponse.campaign(); System.out.println("The Campaign status is " + updatedCampaign.status()); return updatedCampaign.status(); } catch (PersonalizeException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 有关API详细信息,请参阅 “Amazon SDK for Java 2.x API参考 UpdateCampaign” 中的。