public static boolean copyFile()

in amazon-ecs-java-starter-kit-task/src/main/java/software/aws/ecs/java/starterkit/task/ECSTask.java [164:189]


	public static boolean copyFile(S3Client s3, String bucketName, String objectKey, String destinationKey) {
		// Build S3 object key
		String encodedUrl = null;
		boolean objectCopied = false;
		try {
			encodedUrl = URLEncoder.encode(bucketName + "/" + objectKey, StandardCharsets.UTF_8.toString());
		} catch (UnsupportedEncodingException e) {
			System.out.println("URL could not be encoded: " + e.getMessage());
		}
		// Copy object request
		CopyObjectRequest copyReq = CopyObjectRequest.builder().copySource(encodedUrl).destinationBucket(bucketName)
				.destinationKey(destinationKey).build();
		try {
			CopyObjectResponse copyRes = s3.copyObject(copyReq);
			if (copyRes.sdkHttpResponse().isSuccessful()) {
				System.out.println("Copy operation successful");
				objectCopied = true;
			}
			else
				System.out.println("Copy operation not successful");
		} catch (S3Exception e) {
			System.out.println("Exception thrown while copying S3 object");
			System.err.println(e.awsErrorDetails().errorMessage());
		}
		return objectCopied;
	}