use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class ExportEndpoints method main.
public static void main(String[] args) {
final String USAGE = "\n" + "This program performs the following steps:\n\n" + "1) Exports the endpoints to an Amazon S3 bucket.\n" + "2) Downloads the exported endpoints files from Amazon S3.\n" + "3) Parses the endpoints files to obtain the endpoint IDs and prints them.\n" + "Usage: ExportEndpoints <applicationId> <s3BucketName> <iamExportRoleArn> <path>\n\n" + "Where:\n" + " applicationId - The ID of the Amazon Pinpoint application that has the endpoint.\n" + " s3BucketName - The name of the Amazon S3 bucket to export the JSON file to. \n" + " iamExportRoleArn - The ARN of an IAM role that grants Amazon Pinpoint write permissions to the S3 bucket." + " path - The path where the files downloaded from the Amazon S3 bucket are written (for example, C:/AWS/).\n";
if (args.length != 4) {
System.out.println(USAGE);
System.exit(1);
}
String applicationId = args[0];
String s3BucketName = args[1];
String iamExportRoleArn = args[2];
String path = args[3];
System.out.println("Deleting an application with ID: " + applicationId);
Region region = Region.US_EAST_1;
PinpointClient pinpoint = PinpointClient.builder().region(region).build();
S3Client s3Client = S3Client.builder().region(region).build();
exportAllEndpoints(pinpoint, s3Client, applicationId, s3BucketName, path, iamExportRoleArn);
pinpoint.close();
s3Client.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class ExportEndpoints method downloadFromS3.
// Downloads files from an Amazon S3 bucket and writes them to the path location
public static void downloadFromS3(S3Client s3Client, String path, String s3BucketName, List<String> objectKeys) {
try {
for (String key : objectKeys) {
GetObjectRequest objectRequest = GetObjectRequest.builder().bucket(s3BucketName).key(key).build();
ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
// Write the data to a local file
String fileSuffix = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
path = path + fileSuffix + ".gz";
File myFile = new File(path);
OutputStream os = new FileOutputStream(myFile);
os.write(data);
}
System.out.println("Download finished.");
} catch (S3Exception | NullPointerException | IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class ExportEndpoints method exportEndpointsToS3.
public static List<String> exportEndpointsToS3(PinpointClient pinpoint, S3Client s3Client, String s3BucketName, String iamExportRoleArn, String applicationId) {
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 + "/";
List<String> objectKeys = new ArrayList<>();
String key = "";
try {
// Defines the export job that Amazon Pinpoint runs
ExportJobRequest jobRequest = ExportJobRequest.builder().roleArn(iamExportRoleArn).s3UrlPrefix(s3UrlPrefix).build();
CreateExportJobRequest exportJobRequest = CreateExportJobRequest.builder().applicationId(applicationId).exportJobRequest(jobRequest).build();
System.out.format("Exporting endpoints from Amazon Pinpoint application %s to Amazon S3 " + "bucket %s . . .\n", applicationId, s3BucketName);
CreateExportJobResponse exportResult = pinpoint.createExportJob(exportJobRequest);
String jobId = exportResult.exportJobResponse().id();
System.out.println(jobId);
printExportJobStatus(pinpoint, applicationId, jobId);
ListObjectsV2Request v2Request = ListObjectsV2Request.builder().bucket(s3BucketName).prefix(endpointsKeyPrefix).build();
// Create a list of object keys
ListObjectsV2Response v2Response = s3Client.listObjectsV2(v2Request);
List<S3Object> objects = v2Response.contents();
for (S3Object object : objects) {
key = object.key();
objectKeys.add(key);
}
return objectKeys;
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class PPEBoundingBoxFrame method getObjectBytes.
public static byte[] getObjectBytes(S3Client s3, String bucketName, String keyName) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
return data;
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class PPEBoundingBoxFrame method main.
public static void main(String[] args) throws Exception {
final String USAGE = "\n" + "Usage: " + "DisplayFaces <sourceImage> <bucketName>\n\n" + "Where:\n" + "sourceImage - the name of the image in an Amazon S3 bucket that shows a person wearing a mask (for example, masks.png). \n\n" + "bucketName - the name of the Amazon S3 bucket (for example, myBucket). \n\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String sourceImage = args[0];
String bucketName = args[1];
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder().region(region).build();
RekognitionClient rekClient = RekognitionClient.builder().region(region).build();
displayGear(s3, rekClient, sourceImage, bucketName);
s3.close();
rekClient.close();
}
Aggregations