use of com.amazonaws.services.s3.model.AmazonS3Exception in project druid by druid-io.
the class S3Entity method readFrom.
@Override
protected InputStream readFrom(long offset) throws IOException {
final GetObjectRequest request = new GetObjectRequest(object.getBucket(), object.getPath());
request.setRange(offset);
try {
final S3Object s3Object = s3Client.getObject(request);
if (s3Object == null) {
throw new ISE("Failed to get an s3 object for bucket[%s], key[%s], and start[%d]", object.getBucket(), object.getPath(), offset);
}
return s3Object.getObjectContent();
} catch (AmazonS3Exception e) {
throw new IOException(e);
}
}
use of com.amazonaws.services.s3.model.AmazonS3Exception in project druid by druid-io.
the class StaticS3FirehoseFactory method openObjectStream.
@Override
protected InputStream openObjectStream(URI object) throws IOException {
try {
// Get data of the given object and open an input stream
final String bucket = object.getAuthority();
final String key = S3Utils.extractS3Key(object);
final S3Object s3Object = s3Client.getObject(bucket, key);
if (s3Object == null) {
throw new ISE("Failed to get an s3 object for bucket[%s] and key[%s]", bucket, key);
}
return s3Object.getObjectContent();
} catch (AmazonS3Exception e) {
throw new IOException(e);
}
}
use of com.amazonaws.services.s3.model.AmazonS3Exception in project druid by druid-io.
the class ObjectSummaryIterator method fetchNextBatch.
private void fetchNextBatch() {
try {
result = S3Utils.retryS3Operation(() -> s3Client.listObjectsV2(request), maxRetries);
request.setContinuationToken(result.getNextContinuationToken());
objectSummaryIterator = result.getObjectSummaries().iterator();
} catch (AmazonS3Exception e) {
throw new RE(e, "Failed to get object summaries from S3 bucket[%s], prefix[%s]; S3 error: %s", request.getBucketName(), request.getPrefix(), e.getMessage());
} catch (Exception e) {
throw new RE(e, "Failed to get object summaries from S3 bucket[%s], prefix[%s]", request.getBucketName(), request.getPrefix());
}
}
use of com.amazonaws.services.s3.model.AmazonS3Exception in project druid by druid-io.
the class S3InputSourceTest method expectListObjectsAndThrowAccessDenied.
private static void expectListObjectsAndThrowAccessDenied(final URI prefix) {
AmazonS3Exception boom = new AmazonS3Exception("oh dang, you can't list that bucket friend");
boom.setStatusCode(403);
EasyMock.expect(S3_CLIENT.listObjectsV2(matchListObjectsRequest(prefix))).andThrow(boom).once();
}
use of com.amazonaws.services.s3.model.AmazonS3Exception in project aws-doc-sdk-examples by awsdocs.
the class ImportEndpoints method uploadToS3.
private static void uploadToS3(File endpointsFile, String s3BucketName) {
// Initializes Amazon S3 client.
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
// Checks whether the specified bucket exists. If not, attempts to create one.
if (!s3.doesBucketExistV2(s3BucketName)) {
try {
s3.createBucket(s3BucketName);
System.out.format("Created S3 bucket %s.\n", s3BucketName);
} catch (AmazonS3Exception e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
// Uploads the endpoints file to the bucket.
String endpointsFileName = endpointsFile.getName();
System.out.format("Uploading %s to S3 bucket %s . . .\n", endpointsFileName, s3BucketName);
try {
s3.putObject(s3BucketName, "imports/" + endpointsFileName, endpointsFile);
System.out.println("Finished uploading to S3.");
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
}
Aggregations