Skip to content

Added Java Code for Kinesis Lambda Integration #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions integration-kinesis-to-lambda/Handler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package example;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.KinesisEvent;

public class Handler implements RequestHandler<KinesisEvent, Void> {
@Override
public Void handleRequest(final KinesisEvent event, final Context context) {
LambdaLogger logger = context.getLogger();
if (event.getRecords().isEmpty()) {
logger.log("Empty Kinesis Event received");
return null;
}
for (KinesisEvent.KinesisEventRecord record : event.getRecords()) {
try {
logger.log("Processed Event with EventId: "+record.getEventID());
String data = new String(record.getKinesis().getData().array());
logger.log("Data:"+ data);
// TODO: Do interesting work based on the new data
}
catch (Exception ex) {
logger.log("An error occurred:"+ex.getMessage());
throw ex;
}
}
logger.log("Successfully processed:"+event.getRecords().size()+" records");
return null;
}

}
20 changes: 19 additions & 1 deletion integration-kinesis-to-lambda/snippet-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Using AWS Lambda with Amazon Kinesis without Batch Item Handling.",
"type": "Integration",
"services": ["lambda", "kinesis"],
"languages": ["Node", "TypeScript", ".NET"],
"languages": ["Node", "TypeScript", ".NET","Java"],
"tags": [],
"introBox": {
"headline": "How it works",
Expand Down Expand Up @@ -52,6 +52,17 @@
"language": "dotnet"
}
]
},
{
"id": "Java",
"title": "Usage Example with Java",
"description": "Consuming Kinesis event with Lambda using Java without batch item handling.",
"snippets": [
{
"snippetPath": "Handler.java",
"language": "java"
}
]
}
]
}
Expand All @@ -72,6 +83,13 @@
"bio": "Cloud Application Architect at AWS",
"linkedin": "mtomeh",
"twitter": "mtomeh84"
},
{
"headline": "Java Example Presented by Ananthan Rudran",
"name": "Ananthan Rudran",
"image": "https://pbs.twimg.com/profile_images/888727786797412352/DEZ1mRjs_400x400.jpg",
"bio": "Solutions Architect Architect at AWS",
"linkedin": "ananthanr"
}
]
}