in prototype/dispatch/order-dispatcher/src/main/java/com/aws/proto/dispatching/util/aws/S3Utility.java [46:70]
public static void downloadFile(String bucketName, String keyPath, Path localFilePath) {
AwsCredentialsProvider credentialsProvider = CredentialsHelper.getCredentialsProvider();
S3Client s3Client = S3Client.builder()
.credentialsProvider(credentialsProvider)
.region(CredentialsHelper.getRegion())
.build();
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket(bucketName)
.key(keyPath)
.build();
try {
logger.debug("Downloading s3://{}/{} to {}", bucketName, keyPath, localFilePath);
GetObjectResponse getObjectResponse = s3Client.getObject(getObjectRequest, localFilePath);
logger.info("{} from {} was downloaded to {} ({} bytes)", keyPath, bucketName, localFilePath, getObjectResponse.contentLength());
} catch (NoSuchKeyException e) {
logger.error("Key ({}) doesn't exist in S3 Bucket: {}", getObjectRequest.key(), e.getMessage());
} catch (AwsServiceException | SdkClientException e) {
logger.error("Error while downloading file from S3 bucket '{}/{}': {}", bucketName, keyPath, e.getMessage());
} catch(Exception e) {
logger.error("Generic error :: {}", e.getMessage());
}
}