Search in sources :

Example 41 with DeleteObjectRequest

use of com.amazonaws.s3.model.DeleteObjectRequest in project aws-lambda-powertools-java by awslabs.

the class SqsLargeMessageAspectTest method testLargeMessage.

@Test
public void testLargeMessage() {
    when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(s3ObjectWithLargeMessage());
    SQSEvent sqsEvent = messageWithBody("[\"software.amazon.payloadoffloading.PayloadS3Pointer\",{\"s3BucketName\":\"" + BUCKET_NAME + "\",\"s3Key\":\"" + BUCKET_KEY + "\"}]");
    String response = requestHandler.handleRequest(sqsEvent, context);
    assertThat(response).isEqualTo("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) SqsNoDeleteMessageHandler(software.amazon.lambda.powertools.sqs.handlers.SqsNoDeleteMessageHandler) Mock(org.mockito.Mock) LambdaHandlerApiGateway(software.amazon.lambda.powertools.sqs.handlers.LambdaHandlerApiGateway) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Context(com.amazonaws.services.lambda.runtime.Context) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) RequestHandler(com.amazonaws.services.lambda.runtime.RequestHandler) 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) APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) S3Client(software.amazon.awssdk.services.s3.S3Client) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) FailedProcessingLargePayloadException(software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect.FailedProcessingLargePayloadException) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) SqsMessageHandler(software.amazon.lambda.powertools.sqs.handlers.SqsMessageHandler) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) SqsUtils(software.amazon.lambda.powertools.sqs.SqsUtils) 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) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with DeleteObjectRequest

use of com.amazonaws.s3.model.DeleteObjectRequest in project FinalProject-Spring by HangHae99-FinalProject.

the class AwsS3UploadService method deleteFile.

// DeleteObject를 통해 S3 파일 삭제
public void deleteFile(String fileName) {
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, fileName);
    amazonS3.deleteObject(deleteObjectRequest);
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest)

Example 43 with DeleteObjectRequest

use of com.amazonaws.s3.model.DeleteObjectRequest in project OT148-JAVA by alkemyTech.

the class AmazonService method deleteFileFromS3Bucket.

public String deleteFileFromS3Bucket(String fileUrl) {
    String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
    s3client.deleteObject(new DeleteObjectRequest(bucketName + "/", fileName));
    return "Successfully deleted";
}
Also used : DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest)

Example 44 with DeleteObjectRequest

use of com.amazonaws.s3.model.DeleteObjectRequest in project library-of-alexandria by bottomless-archive-project.

the class S3VaultLocation method clear.

/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    final DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(bucketName).key(fileName).build();
    s3Client.deleteObject(deleteObjectRequest);
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest)

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