Search in sources :

Example 6 with DeleteObjectRequest

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));
}
Also used : Path(java.nio.file.Path) DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference)

Example 7 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) SdkException(software.amazon.awssdk.core.exception.SdkException) S3Client(software.amazon.awssdk.services.s3.S3Client) FileStorageException(io.jmix.core.FileStorageException)

Example 8 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) AmazonClientException(com.amazonaws.AmazonClientException) IOException(java.io.IOException)

Example 9 with DeleteObjectRequest

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));
    }
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.openMocks(org.mockito.MockitoAnnotations.openMocks) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Assertions(org.assertj.core.api.Assertions) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) SQSMessage(com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) S3Client(software.amazon.awssdk.services.s3.S3Client) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) StringInputStream(software.amazon.awssdk.utils.StringInputStream) Mockito.never(org.mockito.Mockito.never) Stream(java.util.stream.Stream) SqsLargeMessageAspect(software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) HashMap(java.util.HashMap) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with DeleteObjectRequest

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);
    });
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.openMocks(org.mockito.MockitoAnnotations.openMocks) BeforeEach(org.junit.jupiter.api.BeforeEach) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Assertions(org.assertj.core.api.Assertions) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) SQSMessage(com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) S3Client(software.amazon.awssdk.services.s3.S3Client) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) StringInputStream(software.amazon.awssdk.utils.StringInputStream) Mockito.never(org.mockito.Mockito.never) Stream(java.util.stream.Stream) SqsLargeMessageAspect(software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) HashMap(java.util.HashMap) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DeleteObjectRequest (com.amazonaws.services.s3.model.DeleteObjectRequest)25 DeleteObjectRequest (software.amazon.awssdk.services.s3.model.DeleteObjectRequest)19 IOException (java.io.IOException)11 AmazonClientException (com.amazonaws.AmazonClientException)7 AmazonServiceException (com.amazonaws.AmazonServiceException)7 S3Client (software.amazon.awssdk.services.s3.S3Client)6 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)6 HashMap (java.util.HashMap)4 SdkClientException (com.amazonaws.SdkClientException)3 SQSEvent (com.amazonaws.services.lambda.runtime.events.SQSEvent)3 SQSMessage (com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage)3 DeleteVersionRequest (com.amazonaws.services.s3.model.DeleteVersionRequest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Collections.singletonList (java.util.Collections.singletonList)3 Consumer (java.util.function.Consumer)3 Stream (java.util.stream.Stream)3 Assertions (org.assertj.core.api.Assertions)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3