Skip to content

Add DynamoDB Document API support for DynamoDB Streams #3

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions aws-lambda-java-events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>[1.10.5,)</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>[1.0.0,)</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */

package com.amazonaws.services.lambda.runtime.events.document;

import java.util.ArrayList;
import java.util.List;

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord;

/**
* Represents an Amazon DynamoDB event for use with the DynamoDB Document API.
*/
public class DynamodbDocumentEvent {
private List<DynamodbStreamItem> itemRecords;

private final DynamodbEvent event;

public DynamodbDocumentEvent(DynamodbEvent event) {
if (this.event == null)
throw new IllegalArgumentException("event must be specified");
this.event = event;
}

/**
* Gets the list of DynamoDB event records
*
*/
public List<DynamodbStreamItem> getItemRecords() {
if (itemRecords == null) {
List<DynamodbStreamRecord> src = event.getRecords();
List<DynamodbStreamItem> dst = new ArrayList<DynamodbStreamItem>(
src.size());

for (DynamodbStreamRecord r : src)
dst.add(new DynamodbStreamItem(r));
event.setRecords(null);
itemRecords = dst;
}

return itemRecords;
}

/**
* Sets the list of DynamoDB event records
*
* @param itemRecords
* a list of DynamoDb event records
*/
public void setItemRecords(List<DynamodbStreamItem> itemRecords) {
this.itemRecords = itemRecords;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.amazonaws.services.lambda.runtime.events.document;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;

/**
*
* Dynamodb event handlers implement AWS Lambda Function application logic using
* plain old java objects as input and output.
*
* @param <O> The output parameter type
*/
public abstract class DynamodbEventHandler<O> implements RequestHandler<DynamodbEvent, O> {

/**
* Handles a Dynamodb event using the Document API
*
* @param input The DynamoDB document event
* @param context The Lambda execution environment context object.
* @return The Lambda Function output
*/
public abstract O handleEvent(DynamodbDocumentEvent input, Context context);

@Override
public final O handleRequest(DynamodbEvent input, Context context) {
return handleEvent(new DynamodbDocumentEvent(input), context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
package com.amazonaws.services.lambda.runtime.events.document;

import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent.DynamodbStreamRecord;

/**
* The unit of data of an Amazon DynamoDB event.
*/
public class DynamodbStreamItem extends ItemRecord {
private static final long serialVersionUID = 1L;
private final DynamodbStreamRecord record;

public DynamodbStreamItem(DynamodbStreamRecord record) {
super(record);
this.record = record;
}

/**
* Gets the event source arn of DynamoDB
*
*/
public String getEventSourceARN() {
return record.getEventSourceARN();
}

/**
* Sets the event source arn of DynamoDB
*
* @param eventSourceArn
* A string containing the event source arn
*/
public void setEventSourceARN(String eventSourceARN) {
record.setEventSourceARN(eventSourceARN);
}
}
Loading