use of software.amazon.awssdk.services.s3.model.DeleteObjectsRequest in project druid by druid-io.
the class S3Utils method deleteBucketKeys.
private static void deleteBucketKeys(ServerSideEncryptingAmazonS3 s3Client, String bucket, List<DeleteObjectsRequest.KeyVersion> keysToDelete) throws Exception {
DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucket).withKeys(keysToDelete);
S3Utils.retryS3Operation(() -> {
s3Client.deleteObjects(deleteRequest);
return null;
});
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectsRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteMultiObjects method deleteBucketObjects.
// snippet-start:[s3.java2.delete_many_objects.main]
public static void deleteBucketObjects(S3Client s3, String bucketName) {
// Upload three sample objects to the specfied Amazon S3 bucket.
ArrayList<ObjectIdentifier> keys = new ArrayList<>();
PutObjectRequest putOb = null;
ObjectIdentifier objectId = null;
for (int i = 0; i < 3; i++) {
String keyName = "delete object example " + i;
objectId = ObjectIdentifier.builder().key(keyName).build();
putOb = PutObjectRequest.builder().bucket(bucketName).key(keyName).build();
s3.putObject(putOb, RequestBody.fromString(keyName));
keys.add(objectId);
}
System.out.println(keys.size() + " objects successfully created.");
// Delete multiple objects in one request.
Delete del = Delete.builder().objects(keys).build();
try {
DeleteObjectsRequest multiObjectDeleteRequest = DeleteObjectsRequest.builder().bucket(bucketName).delete(del).build();
s3.deleteObjects(multiObjectDeleteRequest);
System.out.println("Multiple objects are deleted!");
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectsRequest in project aws-doc-sdk-examples by awsdocs.
the class ListEndpointIds method deleteS3Objects.
private static void deleteS3Objects(String s3BucketName, List<String> keys) {
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
String[] keysArray = keys.toArray(new String[keys.size()]);
DeleteObjectsRequest request = new DeleteObjectsRequest(s3BucketName).withKeys(keysArray);
System.out.println("Deleting the following Amazon S3 objects created by Amazon Pinpoint:");
for (String key : keys) {
System.out.println("\t- " + key);
}
try {
s3Client.deleteObjects(request);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Finished deleting objects.");
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectsRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteMultipleObjectsNonVersionedBucket method main.
public static void main(String[] args) throws IOException {
Regions clientRegion = Regions.DEFAULT_REGION;
String bucketName = "*** Bucket name ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).build();
// Upload three sample objects.
ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>();
for (int i = 0; i < 3; i++) {
String keyName = "delete object example " + i;
s3Client.putObject(bucketName, keyName, "Object number " + i + " to be deleted.");
keys.add(new KeyVersion(keyName));
}
System.out.println(keys.size() + " objects successfully created.");
// Delete the sample objects.
DeleteObjectsRequest multiObjectDeleteRequest = new DeleteObjectsRequest(bucketName).withKeys(keys).withQuiet(false);
// Verify that the objects were deleted successfully.
DeleteObjectsResult delObjRes = s3Client.deleteObjects(multiObjectDeleteRequest);
int successfulDeletes = delObjRes.getDeletedObjects().size();
System.out.println(successfulDeletes + " objects successfully deleted.");
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectsRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteMultipleObjectsVersionEnabledBucket method multiObjectVersionedDeleteRemoveDeleteMarkers.
private static void multiObjectVersionedDeleteRemoveDeleteMarkers(DeleteObjectsResult response) {
List<KeyVersion> keyList = new ArrayList<KeyVersion>();
for (DeletedObject deletedObject : response.getDeletedObjects()) {
// Note that the specified version ID is the version ID for the delete marker.
keyList.add(new KeyVersion(deletedObject.getKey(), deletedObject.getDeleteMarkerVersionId()));
}
// Create a request to delete the delete markers.
DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(VERSIONED_BUCKET_NAME).withKeys(keyList);
// Delete the delete markers, leaving the objects intact in the bucket.
DeleteObjectsResult delObjRes = S3_CLIENT.deleteObjects(deleteRequest);
int successfulDeletes = delObjRes.getDeletedObjects().size();
System.out.println(successfulDeletes + " delete markers successfully deleted");
}
Aggregations