use of com.amazonaws.services.pinpoint.AmazonPinpoint in project aws-doc-sdk-examples by awsdocs.
the class ExportEndpoints method exportEndpointsToS3.
public static List<String> exportEndpointsToS3(String s3BucketName, String iamExportRoleArn, String applicationId) {
// The S3 path that Amazon Pinpoint exports the endpoints to.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH_mm:ss.SSS_z");
String endpointsKeyPrefix = "exports/" + applicationId + "_" + dateFormat.format(new Date());
String s3UrlPrefix = "s3://" + s3BucketName + "/" + endpointsKeyPrefix + "/";
// Defines the export job that Amazon Pinpoint runs.
ExportJobRequest exportJobRequest = new ExportJobRequest().withS3UrlPrefix(s3UrlPrefix).withRoleArn(iamExportRoleArn);
CreateExportJobRequest createExportJobRequest = new CreateExportJobRequest().withApplicationId(applicationId).withExportJobRequest(exportJobRequest);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
System.out.format("Exporting endpoints from Amazon Pinpoint application %s to Amazon S3 " + "bucket %s . . .\n", applicationId, s3BucketName);
List<String> objectKeys = null;
try {
// Runs the export job with Amazon Pinpoint.
CreateExportJobResult exportResult = pinpointClient.createExportJob(createExportJobRequest);
// Prints the export job status to the console while the job runs.
String jobId = exportResult.getExportJobResponse().getId();
printExportJobStatus(pinpointClient, applicationId, jobId);
// Initializes the Amazon S3 client.
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
// Lists the objects created by Amazon Pinpoint.
objectKeys = s3Client.listObjectsV2(s3BucketName, endpointsKeyPrefix).getObjectSummaries().stream().map(S3ObjectSummary::getKey).collect(Collectors.toList());
} catch (AmazonServiceException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return objectKeys;
}
Aggregations