I'm trying to delete multiple objects in a bucket using SDK, but when i pass the list of KeyVersions to the method .deleteObjects(deleteObjectsRequest), he actually deletes the objects from my list, but if i pass a list that contain one or more objects that aren't inside the Bucket it deletes the objects found and does not return which objects weren't deleted because wasn't found.
private void deleteMultipleObjectsFromS3(final List<KeyVersion> objectsKeys) {
final DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(this.bucketName)
.withKeys(objectsKeys)
.withQuiet(false);
try {
s3Client.deleteObjects(deleteObjectsRequest);
} catch (final AmazonServiceException e) {
throw new AmazonSdkException(e, e.getErrorMessage(), DELETE_OPERATION,
this.bucketName, objectsKeys.toString());
} catch (SdkClientException e) {
throw new AmazonSdkException(e, e.getLocalizedMessage(), DELETE_OPERATION, this.bucketName, objectsKeys.toString());
}
}
The response get all objects that i passed, i need to inform in the endpoint which objects were, or not, deleted.
I'm using Java SDK version 1.12.181
EDIT 1:
I've also tried to get the objects sumaries, but it returns all objects in the bucket. What i don't want, because some buckets that i'll operate might have more than 100.000 objects.
final ListObjectsV2Result listObjectsV2Result = s3Client.listObjectsV2(listObjectsRequest);
final List<S3ObjectSummary> s3ObjectSummary = listObjectsV2Result.getObjectSummaries();
CodePudding user response:
DeleteItem will still return a successful response if the object does not exist. This is irrespective of SDK version or language as this response is returned by the underlying S3 API.
If you need to know an object has been deleted or not, since you're on the v1 of the Java SDK:
For every object, call
doesObjectExistpassing in the bucket name & object nameIf
trueis returned, add to atoBeDeletedlistIf
falseis returned, add to anotDeletedlistCall
deleteObjectsfor the items intoBeDeletedIf any items failed to be deleted, remove from
toBeDeleted& add tonotDeleted
Anything in notDeleted, was not deleted & anything in toBeDeleted was deleted.

