Skip to content

Commit 7ea99f9

Browse files
msailesraupachz
authored andcommitted
Add S3 batch event and response (aws#179)
1 parent bf2f2fb commit 7ea99f9

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.amazonaws.services.lambda.runtime.events;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Event to represent the payload which is sent to Lambda by S3 Batch to perform a custom
12+
* action.
13+
*
14+
* https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html
15+
*/
16+
17+
@Data
18+
@Builder(setterPrefix = "with")
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
public class S3BatchEvent {
22+
23+
private String invocationSchemaVersion;
24+
private String invocationId;
25+
private Job job;
26+
private List<Task> tasks;
27+
28+
@Data
29+
@Builder(setterPrefix = "with")
30+
@NoArgsConstructor
31+
@AllArgsConstructor
32+
public static class Job {
33+
34+
private String id;
35+
}
36+
37+
@Data
38+
@Builder(setterPrefix = "with")
39+
@NoArgsConstructor
40+
@AllArgsConstructor
41+
public static class Task {
42+
43+
private String taskId;
44+
private String s3Key;
45+
private String s3VersionId;
46+
private String s3BucketArn;
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.amazonaws.services.lambda.runtime.events;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.util.List;
9+
10+
/**
11+
* Event to represent the response which should be returned as part of a S3 Batch custom
12+
* action.
13+
*
14+
* https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html
15+
*/
16+
17+
@Data
18+
@Builder(setterPrefix = "with")
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
public class S3BatchResponse {
22+
23+
private String invocationSchemaVersion;
24+
private ResultCode treatMissingKeysAs;
25+
private String invocationId;
26+
private List<Result> results;
27+
28+
@Data
29+
@Builder(setterPrefix = "with")
30+
@NoArgsConstructor
31+
@AllArgsConstructor
32+
public static class Result {
33+
34+
private String taskId;
35+
private ResultCode resultCode;
36+
private String resultString;
37+
}
38+
39+
public enum ResultCode {
40+
41+
/**
42+
* The task completed normally. If you requested a job completion report,
43+
* the task's result string is included in the report.
44+
*/
45+
Succeeded,
46+
/**
47+
* The task suffered a temporary failure and will be redriven before the job
48+
* completes. The result string is ignored. If this is the final redrive,
49+
* the error message is included in the final report.
50+
*/
51+
TemporaryFailure,
52+
/**
53+
* The task suffered a permanent failure. If you requested a job-completion
54+
* report, the task is marked as Failed and includes the error message
55+
* string. Result strings from failed tasks are ignored.
56+
*/
57+
PermanentFailure
58+
}
59+
60+
public static S3BatchResponseBuilder fromS3BatchEvent(S3BatchEvent s3BatchEvent) {
61+
return S3BatchResponse.builder()
62+
.withInvocationId(s3BatchEvent.getInvocationId())
63+
.withInvocationSchemaVersion(s3BatchEvent.getInvocationSchemaVersion());
64+
}
65+
}

0 commit comments

Comments
 (0)