use of com.amazonaws.s3.model.DeleteObjectRequest in project esop by instaclustr.
the class BaseS3Restorer method delete.
@Override
public void delete(final Path objectKey, boolean nodeAware) throws Exception {
RemoteObjectReference remoteObjectReference;
if (nodeAware) {
remoteObjectReference = objectKeyToNodeAwareRemoteReference(objectKey);
} else {
remoteObjectReference = objectKeyToRemoteReference(objectKey);
}
final Path fileToDelete = Paths.get(request.storageLocation.bucket, remoteObjectReference.canonicalPath);
logger.info("Non dry: " + fileToDelete);
amazonS3.deleteObject(new DeleteObjectRequest(request.storageLocation.bucket, remoteObjectReference.canonicalPath));
}
use of com.amazonaws.s3.model.DeleteObjectRequest in project jmix by jmix-framework.
the class AwsFileStorage method removeFile.
@Override
public void removeFile(FileRef reference) {
try {
S3Client s3Client = s3ClientReference.get();
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(bucket).key(reference.getPath()).build();
s3Client.deleteObject(deleteObjectRequest);
} catch (SdkException e) {
log.error("Error removing file from S3 storage", e);
String message = String.format("Could not delete file %s.", reference.getFileName());
throw new FileStorageException(FileStorageException.Type.IO_EXCEPTION, message);
}
}
use of com.amazonaws.s3.model.DeleteObjectRequest in project daikon by Talend.
the class S3DeletableResource method delete.
@Override
public void delete() throws IOException {
try {
amazonS3.deleteObject(new DeleteObjectRequest(bucket, location));
isDeleted = true;
} catch (AmazonClientException e) {
throw new IOException("Unable to delete '" + location + "' in bucket '" + bucket + "'.", e);
}
}
use of com.amazonaws.s3.model.DeleteObjectRequest in project aws-lambda-powertools-java by awslabs.
the class SqsUtilsLargeMessageTest method testLargeMessageDeleteFromS3Toggle.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testLargeMessageDeleteFromS3Toggle(boolean deleteS3Payload) {
ResponseInputStream<GetObjectResponse> s3Response = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(new ByteArrayInputStream("A big message".getBytes())));
when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(s3Response);
SQSEvent sqsEvent = messageWithBody("[\"software.amazon.payloadoffloading.PayloadS3Pointer\",{\"s3BucketName\":\"" + BUCKET_NAME + "\",\"s3Key\":\"" + BUCKET_KEY + "\"}]");
Map<String, String> sqsMessage = SqsUtils.enrichedMessageFromS3(sqsEvent, deleteS3Payload, sqsMessages -> {
Map<String, String> someBusinessLogic = new HashMap<>();
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
return someBusinessLogic;
});
assertThat(sqsMessage).hasSize(1).containsEntry("Message", "A big message");
if (deleteS3Payload) {
ArgumentCaptor<DeleteObjectRequest> delete = ArgumentCaptor.forClass(DeleteObjectRequest.class);
verify(s3Client).deleteObject(delete.capture());
Assertions.assertThat(delete.getValue()).satisfies((Consumer<DeleteObjectRequest>) deleteObjectRequest -> {
assertThat(deleteObjectRequest.bucket()).isEqualTo(BUCKET_NAME);
assertThat(deleteObjectRequest.key()).isEqualTo(BUCKET_KEY);
});
} else {
verify(s3Client, never()).deleteObject(any(DeleteObjectRequest.class));
}
}
use of com.amazonaws.s3.model.DeleteObjectRequest in project aws-lambda-powertools-java by awslabs.
the class SqsUtilsLargeMessageTest method testLargeMessage.
@Test
public void testLargeMessage() {
ResponseInputStream<GetObjectResponse> s3Response = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(new ByteArrayInputStream("A big message".getBytes())));
when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(s3Response);
SQSEvent sqsEvent = messageWithBody("[\"software.amazon.payloadoffloading.PayloadS3Pointer\",{\"s3BucketName\":\"" + BUCKET_NAME + "\",\"s3Key\":\"" + BUCKET_KEY + "\"}]");
Map<String, String> sqsMessage = SqsUtils.enrichedMessageFromS3(sqsEvent, sqsMessages -> {
Map<String, String> someBusinessLogic = new HashMap<>();
someBusinessLogic.put("Message", sqsMessages.get(0).getBody());
return someBusinessLogic;
});
assertThat(sqsMessage).hasSize(1).containsEntry("Message", "A big message");
ArgumentCaptor<DeleteObjectRequest> delete = ArgumentCaptor.forClass(DeleteObjectRequest.class);
verify(s3Client).deleteObject(delete.capture());
Assertions.assertThat(delete.getValue()).satisfies((Consumer<DeleteObjectRequest>) deleteObjectRequest -> {
assertThat(deleteObjectRequest.bucket()).isEqualTo(BUCKET_NAME);
assertThat(deleteObjectRequest.key()).isEqualTo(BUCKET_KEY);
});
}
Aggregations