Skip to content

Commit c8a7461

Browse files
authored
Merge pull request #88 from rtananthan/main
Added Java Code for Kinesis Lambda Integration
2 parents 218e553 + be0dcd2 commit c8a7461

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package example;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.LambdaLogger;
5+
import com.amazonaws.services.lambda.runtime.RequestHandler;
6+
import com.amazonaws.services.lambda.runtime.events.KinesisEvent;
7+
8+
public class Handler implements RequestHandler<KinesisEvent, Void> {
9+
@Override
10+
public Void handleRequest(final KinesisEvent event, final Context context) {
11+
LambdaLogger logger = context.getLogger();
12+
if (event.getRecords().isEmpty()) {
13+
logger.log("Empty Kinesis Event received");
14+
return null;
15+
}
16+
for (KinesisEvent.KinesisEventRecord record : event.getRecords()) {
17+
try {
18+
logger.log("Processed Event with EventId: "+record.getEventID());
19+
String data = new String(record.getKinesis().getData().array());
20+
logger.log("Data:"+ data);
21+
// TODO: Do interesting work based on the new data
22+
}
23+
catch (Exception ex) {
24+
logger.log("An error occurred:"+ex.getMessage());
25+
throw ex;
26+
}
27+
}
28+
logger.log("Successfully processed:"+event.getRecords().size()+" records");
29+
return null;
30+
}
31+
32+
}

integration-kinesis-to-lambda/snippet-data.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Using AWS Lambda with Amazon Kinesis without Batch Item Handling.",
44
"type": "Integration",
55
"services": ["lambda", "kinesis"],
6-
"languages": ["Node", "TypeScript", ".NET"],
6+
"languages": ["Node", "TypeScript", ".NET","Java"],
77
"tags": [],
88
"introBox": {
99
"headline": "How it works",
@@ -52,6 +52,17 @@
5252
"language": "dotnet"
5353
}
5454
]
55+
},
56+
{
57+
"id": "Java",
58+
"title": "Usage Example with Java",
59+
"description": "Consuming Kinesis event with Lambda using Java without batch item handling.",
60+
"snippets": [
61+
{
62+
"snippetPath": "Handler.java",
63+
"language": "java"
64+
}
65+
]
5566
}
5667
]
5768
}
@@ -72,6 +83,13 @@
7283
"bio": "Cloud Application Architect at AWS",
7384
"linkedin": "mtomeh",
7485
"twitter": "mtomeh84"
86+
},
87+
{
88+
"headline": "Java Example Presented by Ananthan Rudran",
89+
"name": "Ananthan Rudran",
90+
"image": "https://pbs.twimg.com/profile_images/888727786797412352/DEZ1mRjs_400x400.jpg",
91+
"bio": "Solutions Architect Architect at AWS",
92+
"linkedin": "ananthanr"
7593
}
7694
]
7795
}

0 commit comments

Comments
 (0)