diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java new file mode 100644 index 00000000..a3e8d682 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchEvent.java @@ -0,0 +1,48 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Event to represent the payload which is sent to Lambda by S3 Batch to perform a custom + * action. + * + * https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class S3BatchEvent { + + private String invocationSchemaVersion; + private String invocationId; + private Job job; + private List tasks; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Job { + + private String id; + } + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Task { + + private String taskId; + private String s3Key; + private String s3VersionId; + private String s3BucketArn; + } +} \ No newline at end of file diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java new file mode 100644 index 00000000..4fdd1273 --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java @@ -0,0 +1,65 @@ +package com.amazonaws.services.lambda.runtime.events; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Event to represent the response which should be returned as part of a S3 Batch custom + * action. + * + * https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html + */ + +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor +public class S3BatchResponse { + + private String invocationSchemaVersion; + private ResultCode treatMissingKeysAs; + private String invocationId; + private List results; + + @Data + @Builder(setterPrefix = "with") + @NoArgsConstructor + @AllArgsConstructor + public static class Result { + + private String taskId; + private ResultCode resultCode; + private String resultString; + } + + public enum ResultCode { + + /** + * The task completed normally. If you requested a job completion report, + * the task's result string is included in the report. + */ + Succeeded, + /** + * The task suffered a temporary failure and will be redriven before the job + * completes. The result string is ignored. If this is the final redrive, + * the error message is included in the final report. + */ + TemporaryFailure, + /** + * The task suffered a permanent failure. If you requested a job-completion + * report, the task is marked as Failed and includes the error message + * string. Result strings from failed tasks are ignored. + */ + PermanentFailure + } + + public static S3BatchResponseBuilder fromS3BatchEvent(S3BatchEvent s3BatchEvent) { + return S3BatchResponse.builder() + .withInvocationId(s3BatchEvent.getInvocationId()) + .withInvocationSchemaVersion(s3BatchEvent.getInvocationSchemaVersion()); + } +} \ No newline at end of file