Skip to content

Commit 7ac2662

Browse files
committed
complete SESEvent with mixin and tests
1 parent 9fa531e commit 7ac2662

File tree

6 files changed

+175
-12
lines changed

6 files changed

+175
-12
lines changed

aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/SESEvent.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,19 @@ public static class Mail {
5151
private String messageId;
5252
private String[] destination;
5353
private boolean headersTruncated;
54-
private Map<String, String> headers;
54+
private List<Header> headers;
5555
private CommonHeaders commonHeaders;
5656
}
5757

58+
@Data
59+
@AllArgsConstructor
60+
@Builder(setterPrefix = "with")
61+
@NoArgsConstructor
62+
public static class Header {
63+
private String name;
64+
private String value;
65+
}
66+
5867
@Data
5968
@AllArgsConstructor
6069
@Builder(setterPrefix = "with")

aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22

33
package com.amazonaws.services.lambda.runtime.serialization.events;
44

5-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudFormationCustomResourceEventMixin;
6-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudFrontEventMixin;
7-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CloudWatchLogsEventMixin;
8-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.CodeCommitEventMixin;
9-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.ConnectEventMixin;
10-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.DynamodbEventMixin;
11-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.KinesisEventMixin;
12-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SNSEventMixin;
13-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SQSEventMixin;
14-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.ScheduledEventMixin;
15-
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.SecretsManagerRotationEventMixin;
5+
import com.amazonaws.services.lambda.runtime.serialization.events.mixins.*;
166
import com.amazonaws.services.lambda.runtime.serialization.factories.JacksonFactory;
177
import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer;
188
import com.amazonaws.services.lambda.runtime.serialization.util.ReflectUtil;
@@ -73,6 +63,7 @@ public class LambdaEventSerializers {
7363
"com.amazonaws.services.s3.event.S3EventNotification",
7464
"com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification",
7565
"com.amazonaws.services.lambda.runtime.events.S3Event",
66+
"com.amazonaws.services.lambda.runtime.events.SESEvent",
7667
"com.amazonaws.services.lambda.runtime.events.SNSEvent",
7768
"com.amazonaws.services.lambda.runtime.events.SQSEvent")
7869
.collect(Collectors.toList());
@@ -136,6 +127,8 @@ public class LambdaEventSerializers {
136127
ScheduledEventMixin.class),
137128
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SecretsManagerRotationEvent",
138129
SecretsManagerRotationEventMixin.class),
130+
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SESEvent",
131+
SESEventMixin.class),
139132
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SNSEvent",
140133
SNSEventMixin.class),
141134
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SNSEvent$SNSRecord",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.amazonaws.services.lambda.runtime.serialization.events.mixins;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.List;
6+
7+
public abstract class SESEventMixin {
8+
9+
// needed because Jackson expects "records" instead of "Records"
10+
@JsonProperty("Records") abstract List<?> getRecords();
11+
@JsonProperty("Records") abstract void setRecords(List<?> records);
12+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public static ScheduledEvent loadScheduledEvent(String filename) {
9797
return loadEvent(filename, ScheduledEvent.class);
9898
}
9999

100+
public static SESEvent loadSESEvent(String filename) {
101+
return loadEvent(filename, SESEvent.class);
102+
}
103+
100104
public static SNSEvent loadSNSEvent(String filename) {
101105
return loadEvent(filename, SNSEvent.class);
102106
}

aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,13 @@ public void testLoadSecretsManagerRotationEvent() {
300300
.returns("arn:aws:secretsmanager:eu-central-1:123456789012:secret:/powertools/secretparam-xBPaJ5", from(SecretsManagerRotationEvent::getSecretId))
301301
.returns("CreateSecret", from(SecretsManagerRotationEvent::getStep));
302302
}
303+
304+
@Test
305+
public void testLoadSESEvent() {
306+
SESEvent event = EventLoader.loadSESEvent("ses_event.json");
307+
assertThat(event).isNotNull();
308+
assertThat(event.getRecords()).hasSize(1);
309+
assertThat(event.getRecords().get(0).getSes().getMail().getDestination()[0]).isEqualTo("[email protected]");
310+
assertThat(event.getRecords().get(0).getSes().getMail().getHeaders()).hasSize(29);
311+
}
303312
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"Records": [{
3+
"eventSource": "aws:ses",
4+
"eventVersion": "1.0",
5+
"ses": {
6+
"mail": {
7+
"timestamp": "2019-08-05T21:30:02.028Z",
8+
"source": "[email protected]",
9+
"messageId": "EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000",
10+
"destination": ["[email protected]"],
11+
"headersTruncated": false,
12+
"headers": [{
13+
"name": "Return-Path",
14+
"value": "<[email protected]>"
15+
}, {
16+
"name": "Received",
17+
"value": "from smtp.example.com [203.0.113.0]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id bsvpsoklfhu7u50iur7h0kk9a2ou0r7iexample for [email protected];Mon, 05 Aug 2019 21:30:02 +0000 (UTC)"
18+
}, {
19+
"name": "X-SES-Spam-Verdict",
20+
"value": "PASS"
21+
}, {
22+
"name": "X-SES-Virus-Verdict",
23+
"value": "PASS"
24+
}, {
25+
"name": "Received-SPF",
26+
"value": "pass (spfCheck: domain of example.com designates 203.0.113.0 as permitted sender) client-ip=203.0.113.0; [email protected]; helo=smtp.example.com;"
27+
}, {
28+
"name": "Authentication-Results",
29+
"value": "amazonses.com; spf=pass (spfCheck: domain of example.com designates 203.0.113.0as permitted sender) client-ip=203.0.113.0; [email protected]; helo=smtp.example.com; dkim=pass [email protected]; dmarc=none header.from=example.com;"
30+
}, {
31+
"name": "X-SES-RECEIPT",
32+
"value": "AEFBQUFBQUFBQUFHbFo0VU81VzVuYmRDNm51nhTVWpabDh6J4V2l5cG5PSHFtNzlBeUk90example"
33+
}, {
34+
"name": "X-SES-DKIM-SIGNATURE",
35+
"value": "a=rsa-sha256; q=dns/txt; b=Cm1emU30VcD6example=; c=relaxed/simple; s=6gbrjpgwjs5zn6fwqknexample; d=amazonses.com; t=1567719002; v=1; bh=DSofsjAoUvyZj6YsBDP5enpRO1otGb7Nes0Qexample=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-SES-RECEIPT;"
36+
}, {
37+
"name": "DKIM-Signature",
38+
"value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; [email protected]; q=dns/txt; s=example12345; t=1567719001; x=1599255001; h=from:to:subject:date:message-id:references:in-reply-to:mime-version; bh=sjAoUvyZj6YsBDP5enpRO1otGb7s0Qexample=; b=EQw2D4RLOW2IHE9OgfEA4WXp+AENJtaD2+63wmd5J+d+t/xoaiKUGClOS7WhpyOmlipryOz+iOhxUv350xJIHjLTi9Jsnlw76mRK8o4770TaUz620joCVN21n4cxsrRZpv+1kS0EcAxaF30pmwlni+XT4emsVxn7zO0I8example=;"
39+
}, {
40+
"name": "Received",
41+
"value": "from mail.example.com (mail.example.com [203.0.113.0]) by email-inbound-relay-1d-9ec21598.us-east-1.example.com (Postfix) with ESMTPS id 57F83A2042 for <[email protected]>; Mon, 5 Aug 2019 21:29:58 +0000 (UTC)"
42+
}, {
43+
"name": "From",
44+
"value": "\"Doe, John\" <[email protected]>"
45+
}, {
46+
"name": "To",
47+
48+
}, {
49+
"name": "Subject",
50+
"value": "This is a test"
51+
}, {
52+
"name": "Thread-Topic",
53+
"value": "This is a test"
54+
}, {
55+
"name": "Thread-Index",
56+
"value": "AQHVZDAaQ58yKI8q7kaAjkhC5stGexample"
57+
}, {
58+
"name": "Date",
59+
"value": "Mon, 5 Aug 2019 21:29:57 +0000"
60+
}, {
61+
"name": "Message-ID",
62+
"value": "<[email protected]>"
63+
}, {
64+
"name": "References",
65+
"value": "<[email protected]>"
66+
}, {
67+
"name": "In-Reply-To",
68+
"value": "<[email protected]>"
69+
}, {
70+
"name": "Accept-Language",
71+
"value": "en-US"
72+
}, {
73+
"name": "Content-Language",
74+
"value": "en-US"
75+
}, {
76+
"name": "X-MS-Has-Attach",
77+
"value": ""
78+
}, {
79+
"name": "X-MS-TNEF-Correlator",
80+
"value": ""
81+
}, {
82+
"name": "x-ms-exchange-messagesentrepresentingtype",
83+
"value": "1"
84+
}, {
85+
"name": "x-ms-exchange-transport-fromentityheader",
86+
"value": "Hosted"
87+
}, {
88+
"name": "x-originating-ip",
89+
"value": "[203.0.113.0]"
90+
}, {
91+
"name": "Content-Type",
92+
"value": "multipart/alternative; boundary=\"_000_F8098FDD49A344F6112B195BDAexamplecom_\""
93+
}, {
94+
"name": "MIME-Version",
95+
"value": "1.0"
96+
}, {
97+
"name": "Precedence",
98+
"value": "Bulk"
99+
}],
100+
"commonHeaders": {
101+
"returnPath": "[email protected]",
102+
"from": ["\"Doe, John\" <[email protected]>"],
103+
"date": "Mon, 5 Aug 2019 21:29:57 +0000",
104+
105+
"messageId": "<[email protected]>",
106+
"subject": "This is a test"
107+
}
108+
},
109+
"receipt": {
110+
"timestamp": "2019-08-05T21:30:02.028Z",
111+
"processingTimeMillis": 1205,
112+
"recipients": ["[email protected]"],
113+
"spamVerdict": {
114+
"status": "PASS"
115+
},
116+
"virusVerdict": {
117+
"status": "PASS"
118+
},
119+
"spfVerdict": {
120+
"status": "PASS"
121+
},
122+
"dkimVerdict": {
123+
"status": "PASS"
124+
},
125+
"dmarcVerdict": {
126+
"status": "GRAY"
127+
},
128+
"action": {
129+
"type": "Lambda",
130+
"functionArn": "arn:aws:lambda:us-east-1:123456789012:function:IncomingEmail",
131+
"invocationType": "Event"
132+
}
133+
}
134+
}
135+
}]
136+
}

0 commit comments

Comments
 (0)