Skip to content

Commit 126ead2

Browse files
authored
Merge pull request #337 from msailes/eventbridge-event-v4
Adding EventBridgeEvent
2 parents 5ce0f33 + 6dc161a commit 126ead2

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

.github/workflows/aws-lambda-java-events.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ jobs:
2525
with:
2626
java-version: 1.8
2727

28-
# Install base module
28+
# Install required module
29+
- name: Install serialization with Maven
30+
run: mvn -B install --file aws-lambda-java-serialization/pom.xml
31+
2932
- name: Install events with Maven
3033
run: mvn -B install --file aws-lambda-java-events/pom.xml
3134

3235
# Package modules that depend on base module
33-
- name: Package serialization with Maven
34-
run: mvn -B package --file aws-lambda-java-serialization/pom.xml
3536
- name: Package events-sdk-transformer with Maven
3637
run: mvn -B package --file aws-lambda-java-events-sdk-transformer/pom.xml
3738

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5+
* the License. A copy of the License is located at
6+
*
7+
* http://aws.amazon.com/apache2.0
8+
*
9+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
package com.amazonaws.services.lambda.runtime.events;
14+
15+
import com.fasterxml.jackson.annotation.JsonFormat;
16+
import com.fasterxml.jackson.annotation.JsonProperty;
17+
import lombok.AllArgsConstructor;
18+
import lombok.Builder;
19+
import lombok.Data;
20+
import lombok.NoArgsConstructor;
21+
22+
import java.time.Instant;
23+
import java.util.List;
24+
25+
/**
26+
* Object representation of an Amazon EventBridge event.
27+
*
28+
* @see <a href="https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html">Using AWS Lambda with Amazon EventBridge (CloudWatch Events)</a>
29+
*
30+
* @author msailes <[email protected]>
31+
*/
32+
@Data
33+
@Builder(setterPrefix = "with")
34+
@NoArgsConstructor
35+
@AllArgsConstructor
36+
public class EventBridgeEvent<T> {
37+
38+
private String version;
39+
40+
private String id;
41+
42+
@JsonProperty("detail-type")
43+
private String detailType;
44+
45+
private String source;
46+
47+
private String account;
48+
49+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssX", timezone = "UTC")
50+
private Instant time;
51+
52+
private String region;
53+
54+
private List<String> resources;
55+
56+
private T detail;
57+
}

aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/LambdaEventSerializersTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ public void testDynamodbTimeWindowEvent() throws IOException {
300300
assertJsonEqual(expected, actual);
301301
}
302302

303+
@Test
304+
public void testEventBridgeEvent() throws IOException {
305+
String expected = EventUtils.readEvent("eventbridge_event.json");
306+
String actual = deserializeSerializeJsonToString(expected, EventBridgeEvent.class);
307+
308+
assertJsonEqual(expected, actual);
309+
}
310+
303311
@Test
304312
public void testIamPolicyResponse() throws IOException {
305313
String expected = EventUtils.readEvent("iam_policy_response.json");
@@ -516,7 +524,7 @@ public void testTimeWindowEventResponse() throws IOException {
516524
assertJsonEqual(expected, actual);
517525
}
518526

519-
private <T> String deserializeSerializeJsonToString(String expected, Class<T> modelClass) throws IOException {
527+
private <T> String deserializeSerializeJsonToString(String expected, Class<T> modelClass) {
520528
T event = CUSTOM_POJO_SERIALIZER.fromJson(expected, modelClass);
521529
ByteArrayOutputStream baos = new ByteArrayOutputStream();
522530

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0",
3+
"id": "fe8d3c65-xmpl-c5c3-2c87-81584709a377",
4+
"detail-type": "RDS DB Instance Event",
5+
"source": "aws.rds",
6+
"account": "123456789012",
7+
"time": "2020-04-28T07:20:20Z",
8+
"region": "us-east-2",
9+
"resources": [
10+
"arn:aws:rds:us-east-2:123456789012:db:rdz6xmpliljlb1"
11+
],
12+
"detail": {
13+
"EventCategories": [
14+
"backup"
15+
],
16+
"SourceType": "DB_INSTANCE",
17+
"SourceArn": "arn:aws:rds:us-east-2:123456789012:db:rdz6xmpliljlb1",
18+
"Date": "2020-04-28T07:20:20.112Z",
19+
"Message": "Finished DB Instance backup",
20+
"SourceIdentifier": "rdz6xmpliljlb1"
21+
}
22+
}

0 commit comments

Comments
 (0)