CreateDatasetExportJob搭配使用 AWS SDK - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

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

CreateDatasetExportJob搭配使用 AWS SDK

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

Java
SDK适用于 Java 2.x
注意

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

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 ""; }
JavaScript
SDK对于 JavaScript (v3)
注意

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

// Get service clients module and commands using ES6 syntax. import { CreateDatasetExportJobCommand } from "@aws-sdk/client-personalize"; import { personalizeClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeClient = new PersonalizeClient({ region: "REGION"}); // Set the export job parameters. export const datasetExportJobParam = { datasetArn: "DATASET_ARN" /* required */, jobOutput: { s3DataDestination: { path: "S3_DESTINATION_PATH" /* required */, //kmsKeyArn: 'ARN' /* include if your bucket uses AWS KMS for encryption }, }, jobName: "NAME" /* required */, roleArn: "ROLE_ARN" /* required */, }; export const run = async () => { try { const response = await personalizeClient.send( new CreateDatasetExportJobCommand(datasetExportJobParam), ); console.log("Success", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();