Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9218c9c

Browse files
authoredMay 18, 2020
Remove SDK dependencies from events library (#127)
* Bump to 3.0.0 * Update Docs and Release Notes
1 parent 9882774 commit 9218c9c

File tree

18 files changed

+3948
-143
lines changed

18 files changed

+3948
-143
lines changed
 

‎README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ___
3535
<dependency>
3636
<groupId>com.amazonaws</groupId>
3737
<artifactId>aws-lambda-java-events</artifactId>
38-
<version>2.2.8</version>
38+
<version>3.0.0</version>
3939
</dependency>
4040
<dependency>
4141
<groupId>com.amazonaws</groupId>
@@ -58,7 +58,7 @@ ___
5858

5959
```groovy
6060
'com.amazonaws:aws-lambda-java-core:1.2.1'
61-
'com.amazonaws:aws-lambda-java-events:2.2.8'
61+
'com.amazonaws:aws-lambda-java-events:3.0.0'
6262
'com.amazonaws:aws-lambda-java-events-sdk-transformer:1.0.0'
6363
'com.amazonaws:aws-lambda-java-log4j:1.0.1'
6464
'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
@@ -68,7 +68,7 @@ ___
6868

6969
```clojure
7070
[com.amazonaws/aws-lambda-java-core "1.2.1"]
71-
[com.amazonaws/aws-lambda-java-events "2.2.8"]
71+
[com.amazonaws/aws-lambda-java-events "3.0.0"]
7272
[com.amazonaws/aws-lambda-java-events-sdk-transformer "1.0.0"]
7373
[com.amazonaws/aws-lambda-java-log4j "1.0.1"]
7474
[com.amazonaws/aws-lambda-java-log4j2 "1.2.0"]
@@ -78,7 +78,7 @@ ___
7878

7979
```scala
8080
"com.amazonaws" % "aws-lambda-java-core" % "1.2.1"
81-
"com.amazonaws" % "aws-lambda-java-events" % "2.2.8"
81+
"com.amazonaws" % "aws-lambda-java-events" % "3.0.0"
8282
"com.amazonaws" % "aws-lambda-java-events-sdk-transformer" % "1.0.0"
8383
"com.amazonaws" % "aws-lambda-java-log4j" % "1.0.1"
8484
"com.amazonaws" % "aws-lambda-java-log4j2" % "1.2.0"

‎aws-lambda-java-events/README.md

Lines changed: 43 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
# AWS Lambda Java Events v2.0
1+
# AWS Lambda Java Events v3.0
22

3-
### New Event Models Supported
4-
* APIGatewayProxyRequestEvent
5-
* APIGatewayProxyResponseEvent
6-
* APIGatewayV2ProxyRequestEvent
7-
* APIGatewayV2ProxyResponseEvent
8-
* CloudFrontEvent
9-
* CloudWatchLogsEvent
10-
* CodeCommitEvent
11-
* IoTButtonEvent
12-
* KinesisFirehoseEvent
13-
* LexEvent
14-
* ScheduledEvent
3+
### Event Models Supported
4+
* `APIGatewayProxyRequestEvent`
5+
* `APIGatewayProxyResponseEvent`
6+
* `APIGatewayV2ProxyRequestEvent`
7+
* `APIGatewayV2ProxyResponseEvent`
8+
* `CloudFrontEvent`
9+
* `CloudWatchLogsEvent`
10+
* `CodeCommitEvent`
11+
* `CognitoEvent`
12+
* `ConfigEvent`
13+
* `DynamodbEvent`
14+
* `IoTButtonEvent`
15+
* `KinesisAnalyticsFirehoseInputPreprocessingEvent`
16+
* `KinesisAnalyticsInputPreprocessingResponse`
17+
* `KinesisAnalyticsOutputDeliveryEvent`
18+
* `KinesisAnalyticsOutputDeliveryResponse`
19+
* `KinesisAnalyticsStreamsInputPreprocessingEvent`
20+
* `KinesisEvent`
21+
* `KinesisFirehoseEvent`
22+
* `LexEvent`
23+
* `S3Event`
24+
* `ScheduledEvent`
25+
* `SNSEvent`
26+
* `SQSEvent`
1527

16-
### New package inclusion model
17-
The old package inclusion model required users to pull unused dependencies into
18-
their package. We have removed this inclusion so that users' jars will be
19-
smaller, which will results in reduced latency times. Customers using older
20-
versions do not need to make any changes to their existing code.
28+
*As of version `3.0.0`, users are no longer required to pull in SDK dependencies in order to use this library.*
2129

22-
The following event models do not require any SDK dependencies
23-
* APIGatewayProxyRequestEvent
24-
* APIGatewayProxyResponseEvent
25-
* APIGatewayV2ProxyRequestEvent
26-
* APIGatewayV2ProxyResponseEvent
27-
* CloudFrontEvent
28-
* CloudWatchLogsEvent
29-
* CodeCommitEvent
30-
* CognitoEvent
31-
* ConfigEvent
32-
* IoTButtonEvent
33-
* KinesisFirehoseEvent
34-
* LexEvent
35-
* ScheduledEvent
36-
* SNSEvent
3730

38-
so the dependencies section in the pom.xml file would like this
31+
### Getting Started
32+
33+
[Maven](https://maven.apache.org)
3934

4035
```xml
4136
<dependencies>
@@ -48,86 +43,29 @@ so the dependencies section in the pom.xml file would like this
4843
<dependency>
4944
<groupId>com.amazonaws</groupId>
5045
<artifactId>aws-lambda-java-events</artifactId>
51-
<version>2.2.9</version>
46+
<version>3.0.0</version>
5247
</dependency>
5348
...
5449
</dependencies>
5550
```
5651

57-
#### S3 Event
58-
59-
For the S3 event the pom would look like this:
52+
[Gradle](https://gradle.org)
6053

61-
```xml
62-
<dependencies>
63-
...
64-
<dependency>
65-
<groupId>com.amazonaws</groupId>
66-
<artifactId>aws-lambda-java-core</artifactId>
67-
<version>1.2.1</version>
68-
</dependency>
69-
<dependency>
70-
<groupId>com.amazonaws</groupId>
71-
<artifactId>aws-lambda-java-events</artifactId>
72-
<version>2.2.9</version>
73-
</dependency>
74-
<dependency>
75-
<groupId>com.amazonaws</groupId>
76-
<artifactId>aws-java-sdk-s3</artifactId>
77-
<version>1.11.163</version>
78-
</dependency>
79-
...
80-
</dependencies>
54+
```groovy
55+
'com.amazonaws:aws-lambda-java-core:1.2.1'
56+
'com.amazonaws:aws-lambda-java-events:3.0.0'
8157
```
8258

83-
#### Kinesis Event
84-
85-
For the Kinesis event
59+
[Leiningen](http://leiningen.org) and [Boot](http://boot-clj.com)
8660

87-
```xml
88-
<dependencies>
89-
....
90-
<dependency>
91-
<groupId>com.amazonaws</groupId>
92-
<artifactId>aws-lambda-java-core</artifactId>
93-
<version>1.2.1</version>
94-
</dependency>
95-
<dependency>
96-
<groupId>com.amazonaws</groupId>
97-
<artifactId>aws-lambda-java-events</artifactId>
98-
<version>2.2.9</version>
99-
</dependency>
100-
<dependency>
101-
<groupId>com.amazonaws</groupId>
102-
<artifactId>aws-java-sdk-kinesis</artifactId>
103-
<version>1.11.163</version>
104-
</dependency>
105-
...
106-
</dependencies>
61+
```clojure
62+
[com.amazonaws/aws-lambda-java-core "1.2.1"]
63+
[com.amazonaws/aws-lambda-java-events "3.0.0"]
10764
```
10865

109-
#### Dynamodb Event
110-
111-
For the Dynamodb event
66+
[sbt](http://www.scala-sbt.org)
11267

113-
```xml
114-
<dependencies>
115-
...
116-
<dependency>
117-
<groupId>com.amazonaws</groupId>
118-
<artifactId>aws-lambda-java-core</artifactId>
119-
<version>1.2.1</version>
120-
</dependency>
121-
<dependency>
122-
<groupId>com.amazonaws</groupId>
123-
<artifactId>aws-lambda-java-events</artifactId>
124-
<version>2.2.9</version>
125-
</dependency>
126-
<dependency>
127-
<groupId>com.amazonaws</groupId>
128-
<artifactId>aws-java-sdk-dynamodb</artifactId>
129-
<version>1.11.163</version>
130-
</dependency>
131-
...
132-
</dependencies>
133-
```
68+
```scala
69+
"com.amazonaws" % "aws-lambda-java-core" % "1.2.1"
70+
"com.amazonaws" % "aws-lambda-java-events" % "3.0.0"
71+
```

‎aws-lambda-java-events/RELEASE.CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
### May 18, 2020
2+
`3.0.0`:
3+
- Removed AWS SDK v1 dependencies ([#74](https://github.com/aws/aws-lambda-java-libs/issues/74))
4+
- Copied relevant S3, Kinesis and DynamoDB model classes under namespace `com.amazonaws.services.lambda.runtime.events.models`
5+
- S3:
6+
- `S3EventNotification`
7+
- Kinesis:
8+
- `EncryptionType`
9+
- `Record`
10+
- DynamoDB:
11+
- `AttributeValue`
12+
- `Identity`
13+
- `OperationType`
14+
- `Record`
15+
- `StreamRecord`
16+
- `StreamViewType`
17+
118
### May 13, 2020
219
`2.2.9`:
320
- Added field `operationName` to `APIGatewayProxyRequestEvent` ([#126](https://github.com/aws/aws-lambda-java-libs/pull/126))

‎aws-lambda-java-events/pom.xml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.amazonaws</groupId>
77
<artifactId>aws-lambda-java-events</artifactId>
8-
<version>2.2.9</version>
8+
<version>3.0.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>AWS Lambda Java Events Library</name>
@@ -49,23 +49,12 @@
4949
<artifactId>joda-time</artifactId>
5050
<version>2.6</version>
5151
</dependency>
52+
5253
<dependency>
53-
<groupId>com.amazonaws</groupId>
54-
<artifactId>aws-java-sdk-s3</artifactId>
55-
<version>1.11.163</version>
56-
<scope>provided</scope>
57-
</dependency>
58-
<dependency>
59-
<groupId>com.amazonaws</groupId>
60-
<artifactId>aws-java-sdk-kinesis</artifactId>
61-
<version>1.11.163</version>
62-
<scope>provided</scope>
63-
</dependency>
64-
<dependency>
65-
<groupId>com.amazonaws</groupId>
66-
<artifactId>aws-java-sdk-dynamodb</artifactId>
67-
<version>1.11.163</version>
68-
<scope>provided</scope>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-engine</artifactId>
56+
<version>5.5.2</version>
57+
<scope>test</scope>
6958
</dependency>
7059
</dependencies>
7160

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2-
1+
/*
2+
* Copyright 2015-2020 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+
*/
313
package com.amazonaws.services.lambda.runtime.events;
414

5-
import com.amazonaws.services.dynamodbv2.model.Record;
6-
715
import java.io.Serializable;
816
import java.util.List;
917

@@ -19,7 +27,7 @@ public class DynamodbEvent implements Serializable, Cloneable {
1927
/**
2028
* The unit of data of an Amazon DynamoDB event
2129
*/
22-
public static class DynamodbStreamRecord extends Record {
30+
public static class DynamodbStreamRecord extends com.amazonaws.services.lambda.runtime.events.models.dynamodb.Record {
2331

2432
private static final long serialVersionUID = 3638381544604354963L;
2533

@@ -52,7 +60,7 @@ public void setEventSourceARN(String eventSourceARN) {
5260
*
5361
* @return A string representation of this object.
5462
*
55-
* @see java.lang.Object#toString()
63+
* @see Object#toString()
5664
*/
5765
@Override
5866
public String toString() {

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2-
1+
/*
2+
* Copyright 2015-2020 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+
*/
313
package com.amazonaws.services.lambda.runtime.events;
14+
415
import java.io.Serializable;
516
import java.util.List;
617

@@ -16,7 +27,7 @@ public class KinesisEvent implements Serializable, Cloneable {
1627
/**
1728
* The unit of data of an Amazon Kinesis stream
1829
*/
19-
public static class Record extends com.amazonaws.services.kinesis.model.Record {
30+
public static class Record extends com.amazonaws.services.lambda.runtime.events.models.kinesis.Record {
2031

2132
private static final long serialVersionUID = 7856672931457425976L;
2233

@@ -49,7 +60,7 @@ public void setKinesisSchemaVersion(String kinesisSchemaVersion) {
4960
*
5061
* @return A string representation of this object.
5162
*
52-
* @see java.lang.Object#toString()
63+
* @see Object#toString()
5364
*/
5465
@Override
5566
public String toString() {
@@ -109,7 +120,7 @@ public boolean equals(Object obj) {
109120
}
110121

111122
/* (non-Javadoc)
112-
* @see com.amazonaws.services.kinesis.model.Record#hashCode()
123+
* @see com.amazonaws.services.lambda.runtime.events.models.kinesis.Record#hashCode()
113124
*/
114125
@Override
115126
public int hashCode() {
@@ -288,7 +299,7 @@ public void setAwsRegion(String awsRegion) {
288299
*
289300
* @return A string representation of this object.
290301
*
291-
* @see java.lang.Object#toString()
302+
* @see Object#toString()
292303
*/
293304
@Override
294305
public String toString() {
@@ -413,7 +424,7 @@ public void setRecords(List<KinesisEventRecord> records) {
413424
*
414425
* @return A string representation of this object.
415426
*
416-
* @see java.lang.Object#toString()
427+
* @see Object#toString()
417428
*/
418429
@Override
419430
public String toString() {

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
2-
1+
/*
2+
* Copyright 2015-2020 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+
*/
313
package com.amazonaws.services.lambda.runtime.events;
414

5-
import com.amazonaws.services.s3.event.S3EventNotification;
15+
import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification;
616

717
import java.io.Serializable;
818
import java.util.ArrayList;
@@ -28,7 +38,7 @@ public S3Event() {
2838
* Create a new instance of S3Event
2939
* @param records A list of S3 event notification records
3040
*/
31-
public S3Event(List<S3EventNotification.S3EventNotificationRecord> records) {
41+
public S3Event(List<S3EventNotificationRecord> records) {
3242
super(records);
3343
}
3444

‎aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/AttributeValue.java

Lines changed: 1111 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* Copyright 2020 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.models.dynamodb;
14+
15+
import java.io.Serializable;
16+
17+
/**
18+
* <p>
19+
* Contains details about the type of identity that made the request.
20+
* </p>
21+
*
22+
* @see <a href="http://docs.aws.amazon.com/goto/WebAPI/streams-dynamodb-2012-08-10/Identity" target="_top">AWS API
23+
* Documentation</a>
24+
*/
25+
public class Identity implements Serializable, Cloneable {
26+
27+
/**
28+
* <p>
29+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
30+
* "dynamodb.amazonaws.com".
31+
* </p>
32+
*/
33+
private String principalId;
34+
35+
/**
36+
* <p>
37+
* The type of the identity. For Time To Live, the type is "Service".
38+
* </p>
39+
*/
40+
private String type;
41+
42+
/**
43+
* <p>
44+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
45+
* "dynamodb.amazonaws.com".
46+
* </p>
47+
*
48+
* @param principalId
49+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
50+
* "dynamodb.amazonaws.com".
51+
*/
52+
public void setPrincipalId(String principalId) {
53+
this.principalId = principalId;
54+
}
55+
56+
/**
57+
* <p>
58+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
59+
* "dynamodb.amazonaws.com".
60+
* </p>
61+
*
62+
* @return A unique identifier for the entity that made the call. For Time To Live, the principalId is
63+
* "dynamodb.amazonaws.com".
64+
*/
65+
public String getPrincipalId() {
66+
return this.principalId;
67+
}
68+
69+
/**
70+
* <p>
71+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
72+
* "dynamodb.amazonaws.com".
73+
* </p>
74+
*
75+
* @param principalId
76+
* A unique identifier for the entity that made the call. For Time To Live, the principalId is
77+
* "dynamodb.amazonaws.com".
78+
* @return Returns a reference to this object so that method calls can be chained together.
79+
*/
80+
public Identity withPrincipalId(String principalId) {
81+
setPrincipalId(principalId);
82+
return this;
83+
}
84+
85+
/**
86+
* <p>
87+
* The type of the identity. For Time To Live, the type is "Service".
88+
* </p>
89+
*
90+
* @param type
91+
* The type of the identity. For Time To Live, the type is "Service".
92+
*/
93+
public void setType(String type) {
94+
this.type = type;
95+
}
96+
97+
/**
98+
* <p>
99+
* The type of the identity. For Time To Live, the type is "Service".
100+
* </p>
101+
*
102+
* @return The type of the identity. For Time To Live, the type is "Service".
103+
*/
104+
public String getType() {
105+
return this.type;
106+
}
107+
108+
/**
109+
* <p>
110+
* The type of the identity. For Time To Live, the type is "Service".
111+
* </p>
112+
*
113+
* @param type
114+
* The type of the identity. For Time To Live, the type is "Service".
115+
* @return Returns a reference to this object so that method calls can be chained together.
116+
*/
117+
public Identity withType(String type) {
118+
setType(type);
119+
return this;
120+
}
121+
122+
/**
123+
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
124+
* redacted from this string using a placeholder value.
125+
*
126+
* @return A string representation of this object.
127+
*
128+
* @see Object#toString()
129+
*/
130+
@Override
131+
public String toString() {
132+
StringBuilder sb = new StringBuilder();
133+
sb.append("{");
134+
if (getPrincipalId() != null)
135+
sb.append("PrincipalId: ").append(getPrincipalId()).append(",");
136+
if (getType() != null)
137+
sb.append("Type: ").append(getType());
138+
sb.append("}");
139+
return sb.toString();
140+
}
141+
142+
@Override
143+
public boolean equals(Object obj) {
144+
if (this == obj)
145+
return true;
146+
if (obj == null)
147+
return false;
148+
149+
if (obj instanceof Identity == false)
150+
return false;
151+
Identity other = (Identity) obj;
152+
if (other.getPrincipalId() == null ^ this.getPrincipalId() == null)
153+
return false;
154+
if (other.getPrincipalId() != null && other.getPrincipalId().equals(this.getPrincipalId()) == false)
155+
return false;
156+
if (other.getType() == null ^ this.getType() == null)
157+
return false;
158+
if (other.getType() != null && other.getType().equals(this.getType()) == false)
159+
return false;
160+
return true;
161+
}
162+
163+
@Override
164+
public int hashCode() {
165+
final int prime = 31;
166+
int hashCode = 1;
167+
168+
hashCode = prime * hashCode + ((getPrincipalId() == null) ? 0 : getPrincipalId().hashCode());
169+
hashCode = prime * hashCode + ((getType() == null) ? 0 : getType().hashCode());
170+
return hashCode;
171+
}
172+
173+
@Override
174+
public Identity clone() {
175+
try {
176+
return (Identity) super.clone();
177+
} catch (CloneNotSupportedException e) {
178+
throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e);
179+
}
180+
}
181+
182+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2020 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.models.dynamodb;
14+
15+
public enum OperationType {
16+
17+
INSERT("INSERT"),
18+
MODIFY("MODIFY"),
19+
REMOVE("REMOVE");
20+
21+
private String value;
22+
23+
private OperationType(String value) {
24+
this.value = value;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return this.value;
30+
}
31+
32+
/**
33+
* Use this in place of valueOf.
34+
*
35+
* @param value
36+
* real value
37+
* @return OperationType corresponding to the value
38+
*
39+
* @throws IllegalArgumentException
40+
* If the specified value does not map to one of the known values in this enum.
41+
*/
42+
public static OperationType fromValue(String value) {
43+
if (value == null || "".equals(value)) {
44+
throw new IllegalArgumentException("Value cannot be null or empty!");
45+
}
46+
47+
for (OperationType enumEntry : OperationType.values()) {
48+
if (enumEntry.toString().equals(value)) {
49+
return enumEntry;
50+
}
51+
}
52+
throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
53+
}
54+
}

‎aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/Record.java

Lines changed: 801 additions & 0 deletions
Large diffs are not rendered by default.

‎aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/dynamodb/StreamRecord.java

Lines changed: 645 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2020 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.models.dynamodb;
14+
15+
public enum StreamViewType {
16+
17+
NEW_IMAGE("NEW_IMAGE"),
18+
OLD_IMAGE("OLD_IMAGE"),
19+
NEW_AND_OLD_IMAGES("NEW_AND_OLD_IMAGES"),
20+
KEYS_ONLY("KEYS_ONLY");
21+
22+
private String value;
23+
24+
StreamViewType(String value) {
25+
this.value = value;
26+
}
27+
28+
public String getValue() {
29+
return value;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return this.value;
35+
}
36+
37+
/**
38+
* Use this in place of valueOf.
39+
*
40+
* @param value real value
41+
* @return StreamViewType corresponding to the value
42+
*
43+
* @throws IllegalArgumentException
44+
* If the specified value does not map to one of the known values in this enum.
45+
*/
46+
public static StreamViewType fromValue(String value) {
47+
if (value == null || "".equals(value)) {
48+
throw new IllegalArgumentException("Value cannot be null or empty!");
49+
}
50+
51+
for (StreamViewType enumEntry : StreamViewType.values()) {
52+
if (enumEntry.toString().equals(value)) {
53+
return enumEntry;
54+
}
55+
}
56+
57+
throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2020 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.models.kinesis;
14+
15+
public enum EncryptionType {
16+
17+
NONE("NONE"),
18+
KMS("KMS");
19+
20+
private String value;
21+
22+
private EncryptionType(String value) {
23+
this.value = value;
24+
}
25+
26+
@Override
27+
public String toString() {
28+
return this.value;
29+
}
30+
31+
/**
32+
* Use this in place of valueOf.
33+
*
34+
* @param value
35+
* real value
36+
* @return EncryptionType corresponding to the value
37+
*
38+
* @throws IllegalArgumentException
39+
* If the specified value does not map to one of the known values in this enum.
40+
*/
41+
public static EncryptionType fromValue(String value) {
42+
if (value == null || "".equals(value)) {
43+
throw new IllegalArgumentException("Value cannot be null or empty!");
44+
}
45+
46+
for (EncryptionType enumEntry : EncryptionType.values()) {
47+
if (enumEntry.toString().equals(value)) {
48+
return enumEntry;
49+
}
50+
}
51+
52+
throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
53+
}
54+
}

‎aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/models/kinesis/Record.java

Lines changed: 494 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/*
2+
* Copyright 2020 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.models.s3;
14+
15+
import org.joda.time.DateTime;
16+
17+
import java.io.UnsupportedEncodingException;
18+
import java.net.URLDecoder;
19+
import java.util.List;
20+
21+
/**
22+
* A helper class that represents a strongly typed S3 EventNotification item sent
23+
* to SQS, SNS, or Lambda.
24+
*/
25+
public class S3EventNotification {
26+
27+
private final List<S3EventNotificationRecord> records;
28+
29+
public S3EventNotification(List<S3EventNotificationRecord> records) {
30+
this.records = records;
31+
}
32+
33+
/**
34+
* @return the records in this notification
35+
*/
36+
public List<S3EventNotificationRecord> getRecords() {
37+
return records;
38+
}
39+
40+
41+
public static class UserIdentityEntity {
42+
43+
private final String principalId;
44+
45+
public UserIdentityEntity(String principalId) {
46+
this.principalId = principalId;
47+
}
48+
49+
public String getPrincipalId() {
50+
return principalId;
51+
}
52+
}
53+
54+
public static class S3BucketEntity {
55+
56+
private final String name;
57+
private final UserIdentityEntity ownerIdentity;
58+
private final String arn;
59+
60+
public S3BucketEntity(String name, UserIdentityEntity ownerIdentity, String arn) {
61+
this.name = name;
62+
this.ownerIdentity = ownerIdentity;
63+
this.arn = arn;
64+
}
65+
66+
public String getName() {
67+
return name;
68+
}
69+
70+
public UserIdentityEntity getOwnerIdentity() {
71+
return ownerIdentity;
72+
}
73+
74+
public String getArn() {
75+
return arn;
76+
}
77+
}
78+
79+
public static class S3ObjectEntity {
80+
81+
private final String key;
82+
private final Long size;
83+
private final String eTag;
84+
private final String versionId;
85+
private final String sequencer;
86+
87+
@Deprecated
88+
public S3ObjectEntity(
89+
String key,
90+
Integer size,
91+
String eTag,
92+
String versionId)
93+
{
94+
this.key = key;
95+
this.size = size == null ? null : size.longValue();
96+
this.eTag = eTag;
97+
this.versionId = versionId;
98+
this.sequencer = null;
99+
}
100+
101+
@Deprecated
102+
public S3ObjectEntity(
103+
String key,
104+
Long size,
105+
String eTag,
106+
String versionId)
107+
{
108+
this(key, size, eTag, versionId, null);
109+
}
110+
111+
public S3ObjectEntity(String key, Long size, String eTag, String versionId, String sequencer) {
112+
this.key = key;
113+
this.size = size;
114+
this.eTag = eTag;
115+
this.versionId = versionId;
116+
this.sequencer = sequencer;
117+
}
118+
119+
public String getKey() {
120+
return key;
121+
}
122+
123+
/**
124+
* S3 URL encodes the key of the object involved in the event. This is
125+
* a convenience method to automatically URL decode the key.
126+
* @return The URL decoded object key.
127+
*/
128+
public String getUrlDecodedKey() {
129+
return urlDecode(getKey());
130+
}
131+
132+
private static final String DEFAULT_ENCODING = "UTF-8";
133+
134+
/**
135+
* Decode a string for use in the path of a URL; uses URLDecoder.decode,
136+
* which decodes a string for use in the query portion of a URL.
137+
*
138+
* @param value The value to decode
139+
* @return The decoded value if parameter is not null, otherwise, null is returned.
140+
*/
141+
private static String urlDecode(final String value) {
142+
if (value == null) {
143+
return null;
144+
}
145+
146+
try {
147+
return URLDecoder.decode(value, DEFAULT_ENCODING);
148+
} catch (UnsupportedEncodingException ex) {
149+
throw new RuntimeException(ex);
150+
}
151+
}
152+
153+
/**
154+
* @deprecated use {@link #getSizeAsLong()} instead.
155+
*/
156+
@Deprecated
157+
public Integer getSize() {
158+
return size == null ? null : size.intValue();
159+
}
160+
161+
public Long getSizeAsLong() {
162+
return size;
163+
}
164+
165+
public String geteTag() {
166+
return eTag;
167+
}
168+
169+
public String getVersionId() {
170+
return versionId;
171+
}
172+
173+
public String getSequencer() {
174+
return sequencer;
175+
}
176+
}
177+
178+
public static class S3Entity {
179+
180+
private final String configurationId;
181+
private final S3BucketEntity bucket;
182+
private final S3ObjectEntity object;
183+
private final String s3SchemaVersion;
184+
185+
public S3Entity(String configurationId, S3BucketEntity bucket, S3ObjectEntity object, String s3SchemaVersion) {
186+
this.configurationId = configurationId;
187+
this.bucket = bucket;
188+
this.object = object;
189+
this.s3SchemaVersion = s3SchemaVersion;
190+
}
191+
192+
public String getConfigurationId() {
193+
return configurationId;
194+
}
195+
196+
public S3BucketEntity getBucket() {
197+
return bucket;
198+
}
199+
200+
public S3ObjectEntity getObject() {
201+
return object;
202+
}
203+
204+
public String getS3SchemaVersion() {
205+
return s3SchemaVersion;
206+
}
207+
}
208+
209+
public static class RequestParametersEntity {
210+
211+
private final String sourceIPAddress;
212+
213+
public RequestParametersEntity(String sourceIPAddress) {
214+
this.sourceIPAddress = sourceIPAddress;
215+
}
216+
217+
public String getSourceIPAddress() {
218+
return sourceIPAddress;
219+
}
220+
}
221+
222+
public static class ResponseElementsEntity {
223+
224+
private final String xAmzId2;
225+
private final String xAmzRequestId;
226+
227+
public ResponseElementsEntity(String xAmzId2, String xAmzRequestId)
228+
{
229+
this.xAmzId2 = xAmzId2;
230+
this.xAmzRequestId = xAmzRequestId;
231+
}
232+
233+
public String getxAmzId2() {
234+
return xAmzId2;
235+
}
236+
237+
public String getxAmzRequestId() {
238+
return xAmzRequestId;
239+
}
240+
}
241+
242+
public static class S3EventNotificationRecord {
243+
244+
private final String awsRegion;
245+
private final String eventName;
246+
private final String eventSource;
247+
private DateTime eventTime;
248+
private final String eventVersion;
249+
private final RequestParametersEntity requestParameters;
250+
private final ResponseElementsEntity responseElements;
251+
private final S3Entity s3;
252+
private final UserIdentityEntity userIdentity;
253+
254+
public S3EventNotificationRecord(String awsRegion, String eventName, String eventSource, String eventTime,
255+
String eventVersion, RequestParametersEntity requestParameters,
256+
ResponseElementsEntity responseElements, S3Entity s3,
257+
UserIdentityEntity userIdentity) {
258+
this.awsRegion = awsRegion;
259+
this.eventName = eventName;
260+
this.eventSource = eventSource;
261+
262+
if (eventTime != null)
263+
{
264+
this.eventTime = DateTime.parse(eventTime);
265+
}
266+
267+
this.eventVersion = eventVersion;
268+
this.requestParameters = requestParameters;
269+
this.responseElements = responseElements;
270+
this.s3 = s3;
271+
this.userIdentity = userIdentity;
272+
}
273+
274+
public String getAwsRegion() {
275+
return awsRegion;
276+
}
277+
278+
public String getEventName() {
279+
return eventName;
280+
}
281+
282+
public String getEventSource() {
283+
return eventSource;
284+
}
285+
286+
public DateTime getEventTime() {
287+
return eventTime;
288+
}
289+
290+
public String getEventVersion() {
291+
return eventVersion;
292+
}
293+
294+
public RequestParametersEntity getRequestParameters() {
295+
return requestParameters;
296+
}
297+
298+
public ResponseElementsEntity getResponseElements() {
299+
return responseElements;
300+
}
301+
302+
public S3Entity getS3() {
303+
return s3;
304+
}
305+
306+
public UserIdentityEntity getUserIdentity() {
307+
return userIdentity;
308+
}
309+
}
310+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2020 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 java.io.UnsupportedEncodingException;
16+
import java.net.URLEncoder;
17+
import java.util.regex.Matcher;
18+
import java.util.regex.Pattern;
19+
20+
public class HttpUtils {
21+
22+
private static final String DEFAULT_ENCODING = "UTF-8";
23+
24+
/**
25+
* Regex which matches any of the sequences that we need to fix up after
26+
* URLEncoder.encode().
27+
*/
28+
private static final Pattern ENCODED_CHARACTERS_PATTERN;
29+
static {
30+
StringBuilder pattern = new StringBuilder()
31+
.append(Pattern.quote("+"))
32+
.append("|")
33+
.append(Pattern.quote("*"))
34+
.append("|")
35+
.append(Pattern.quote("%7E"))
36+
.append("|")
37+
.append(Pattern.quote("%2F"));
38+
39+
ENCODED_CHARACTERS_PATTERN = Pattern.compile(pattern.toString());
40+
}
41+
42+
/**
43+
* Encode a string for use in the path of a URL; uses URLEncoder.encode,
44+
* (which encodes a string for use in the query portion of a URL), then
45+
* applies some postfilters to fix things up per the RFC. Can optionally
46+
* handle strings which are meant to encode a path (ie include '/'es
47+
* which should NOT be escaped).
48+
*
49+
* @param value the value to encode
50+
* @param path true if the value is intended to represent a path
51+
* @return the encoded value
52+
*/
53+
public static String urlEncode(final String value, final boolean path) {
54+
if (value == null) {
55+
return "";
56+
}
57+
58+
try {
59+
String encoded = URLEncoder.encode(value, DEFAULT_ENCODING);
60+
61+
Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded);
62+
StringBuffer buffer = new StringBuffer(encoded.length());
63+
64+
while (matcher.find()) {
65+
String replacement = matcher.group(0);
66+
67+
if ("+".equals(replacement)) {
68+
replacement = "%20";
69+
} else if ("*".equals(replacement)) {
70+
replacement = "%2A";
71+
} else if ("%7E".equals(replacement)) {
72+
replacement = "~";
73+
} else if (path && "%2F".equals(replacement)) {
74+
replacement = "/";
75+
}
76+
77+
matcher.appendReplacement(buffer, replacement);
78+
}
79+
80+
matcher.appendTail(buffer);
81+
return buffer.toString();
82+
83+
} catch (UnsupportedEncodingException ex) {
84+
throw new RuntimeException(ex);
85+
}
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 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.models.s3;
14+
15+
import com.amazonaws.services.lambda.runtime.events.HttpUtils;
16+
import org.junit.jupiter.api.Assertions;
17+
import org.junit.jupiter.api.Test;
18+
19+
import java.util.Arrays;
20+
import java.util.List;
21+
22+
public class S3EventNotificationTest {
23+
24+
private List<String> KEYS_REQUIRING_URL_ENCODE = Arrays.asList("foo bar.jpg", "foo/bar.csv", "foo<>bar");
25+
26+
@Test
27+
public void testGetUrlDecodedKey() {
28+
for (String testKey : KEYS_REQUIRING_URL_ENCODE) {
29+
String urlEncoded = HttpUtils.urlEncode(testKey, false);
30+
S3EventNotification.S3ObjectEntity entity = new S3EventNotification.S3ObjectEntity(
31+
urlEncoded, 1L, "E-Tag", "versionId");
32+
Assertions.assertEquals(testKey, entity.getUrlDecodedKey());
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.