Skip to content

Commit aa399f5

Browse files
mmerfortsmirnoal
andauthored
Add S3BatchEventV2 (#496)
* Add S3BatchEventV2 class * Add test for S3BatchEventV2 --------- Co-authored-by: Martin Merfort <[email protected]> Co-authored-by: Alexander Smirnov <[email protected]>
1 parent a36e041 commit aa399f5

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
import java.util.Map;
10+
11+
/**
12+
* Event to represent the payload which is sent to Lambda by S3 Batch to perform a custom
13+
* action when using invocation schema version 2.0.
14+
*
15+
* https://docs.aws.amazon.com/AmazonS3/latest/dev/batch-ops-invoke-lambda.html
16+
*/
17+
18+
@Data
19+
@Builder(setterPrefix = "with")
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
public class S3BatchEventV2 {
23+
24+
private String invocationSchemaVersion;
25+
private String invocationId;
26+
private Job job;
27+
private List<Task> tasks;
28+
29+
@Data
30+
@Builder(setterPrefix = "with")
31+
@NoArgsConstructor
32+
@AllArgsConstructor
33+
public static class Job {
34+
35+
private String id;
36+
private Map<String, String> userArguments;
37+
}
38+
39+
@Data
40+
@Builder(setterPrefix = "with")
41+
@NoArgsConstructor
42+
@AllArgsConstructor
43+
public static class Task {
44+
45+
private String taskId;
46+
private String s3Key;
47+
private String s3VersionId;
48+
private String s3BucketName;
49+
}
50+
}

Diff for: aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/S3BatchResponse.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,10 @@ public static S3BatchResponseBuilder fromS3BatchEvent(S3BatchEvent s3BatchEvent)
6262
.withInvocationId(s3BatchEvent.getInvocationId())
6363
.withInvocationSchemaVersion(s3BatchEvent.getInvocationSchemaVersion());
6464
}
65-
}
65+
66+
public static S3BatchResponseBuilder fromS3BatchEvent(S3BatchEventV2 s3BatchEvent) {
67+
return S3BatchResponse.builder()
68+
.withInvocationId(s3BatchEvent.getInvocationId())
69+
.withInvocationSchemaVersion(s3BatchEvent.getInvocationSchemaVersion());
70+
}
71+
}

Diff for: aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public static S3Event loadS3Event(String filename) {
105105
return loadEvent(filename, S3Event.class);
106106
}
107107

108+
public static S3BatchEventV2 loadS3BatchEventV2(String filename) {
109+
return loadEvent(filename, S3BatchEventV2.class);
110+
}
111+
108112
public static SecretsManagerRotationEvent loadSecretsManagerRotationEvent(String filename) {
109113
return loadEvent(filename, SecretsManagerRotationEvent.class);
110114
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.amazonaws.services.lambda.runtime.tests;
2+
3+
import com.amazonaws.services.lambda.runtime.events.S3BatchEventV2;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.*;
7+
8+
public class S3BatchEventV2Test {
9+
10+
@Test
11+
public void testS3BatchEventV2() {
12+
S3BatchEventV2 event = EventLoader.loadS3BatchEventV2("s3_batch_event_v2.json");
13+
assertThat(event).isNotNull();
14+
assertThat(event.getInvocationId()).isEqualTo("Jr3s8KZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZzatx7Ruy");
15+
assertThat(event.getJob()).isNotNull();
16+
assertThat(event.getJob().getUserArguments().get("MyDestinationBucket")).isEqualTo("destination-directory-bucket-name");
17+
assertThat(event.getTasks()).hasSize(1);
18+
assertThat(event.getTasks().get(0).getS3Key()).isEqualTo("s3objectkey");
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"invocationSchemaVersion": "2.0",
3+
"invocationId": "Jr3s8KZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZzatx7Ruy",
4+
"job": {
5+
"id": "ry77cd60-61f6-4a2b-8a21-d07600c874gf",
6+
"userArguments": {
7+
"MyDestinationBucket": "destination-directory-bucket-name",
8+
"MyDestinationBucketRegion": "us-east-1",
9+
"MyDestinationPrefix": "copied/",
10+
"MyDestinationObjectKeySuffix": "_new_suffix"
11+
}
12+
},
13+
"tasks": [
14+
{
15+
"taskId": "y5R3a2lkZ29lc2hlurcS",
16+
"s3Key": "s3objectkey",
17+
"s3VersionId": null,
18+
"s3Bucket": "source-directory-bucket-name"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)