Skip to content

Commit 490742c

Browse files
authored
Merge pull request #184 from mythilias/main
Java example for the Lambda-DynamoDB integration
2 parents 59982a2 + 8072bf4 commit 490742c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import com.amazonaws.services.lambda.runtime.Context;
2+
import com.amazonaws.services.lambda.runtime.RequestHandler;
3+
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
4+
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord;
5+
import com.google.gson.Gson;
6+
import com.google.gson.GsonBuilder;
7+
8+
public class example implements RequestHandler<DynamodbEvent, Void> {
9+
10+
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
11+
12+
@Override
13+
public Void handleRequest(DynamodbEvent event, Context context) {
14+
System.out.println(GSON.toJson(event));
15+
event.getRecords().forEach(this::logDynamoDBRecord);
16+
return null;
17+
}
18+
19+
private void logDynamoDBRecord(DynamodbStreamRecord record) {
20+
System.out.println(record.getEventID());
21+
System.out.println(record.getEventName());
22+
System.out.println("DynamoDB Record: " + GSON.toJson(record.getDynamodb()));
23+
}
24+
}

0 commit comments

Comments
 (0)