Search in sources :

Example 11 with AmazonPinpoint

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;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Date(java.util.Date)

Aggregations

AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)11 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AddressConfiguration (com.amazonaws.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (com.amazonaws.services.pinpoint.model.DirectMessageConfiguration)2 EndpointResponse (com.amazonaws.services.pinpoint.model.EndpointResponse)2 EndpointUser (com.amazonaws.services.pinpoint.model.EndpointUser)2 MessageRequest (com.amazonaws.services.pinpoint.model.MessageRequest)2 SendMessagesRequest (com.amazonaws.services.pinpoint.model.SendMessagesRequest)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CreateImportJobRequest (com.amazonaws.services.pinpoint.model.CreateImportJobRequest)1 CreateImportJobResult (com.amazonaws.services.pinpoint.model.CreateImportJobResult)1 DeleteEndpointRequest (com.amazonaws.services.pinpoint.model.DeleteEndpointRequest)1 DeleteEndpointResult (com.amazonaws.services.pinpoint.model.DeleteEndpointResult)1 EmailMessage (com.amazonaws.services.pinpoint.model.EmailMessage)1 EndpointBatchItem (com.amazonaws.services.pinpoint.model.EndpointBatchItem)1 EndpointBatchRequest (com.amazonaws.services.pinpoint.model.EndpointBatchRequest)1 EndpointRequest (com.amazonaws.services.pinpoint.model.EndpointRequest)1 GetEndpointRequest (com.amazonaws.services.pinpoint.model.GetEndpointRequest)1 GetEndpointResult (com.amazonaws.services.pinpoint.model.GetEndpointResult)1