Use CreateDatasetExportJob with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateDatasetExportJob with an AWS SDK

The following code examples show how to use CreateDatasetExportJob.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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 for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

// 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();