Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Example lightweight DynamoDB integration that limits AWS Lambda cold starts for Java

License

NotificationsYou must be signed in to change notification settings

rjozefowicz/rapid-dynamodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example lightweight DynamoDB integration that limits AWS Lambda cold starts for Java. It is pure-Java8 implementation without third-part libraries that increases fat JAR size and cold starts time.

It uses DynamoDB Low-Level API described onhttps://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Operations_Amazon_DynamoDB.html

Getting Started

Example AWS Lambda

This example assumes that there is DynamoDB TableTest created with Primary Keyuuid with String type. It uses JSR-374 JSONP as JSON parser (https://javaee.github.io/jsonp/) for better readibility during preparing JSON requests.

JSON request in the following format:

{"uuid":"NEW_UUID"}

Maven dependencies:

<dependencies>        <dependency>            <groupId>com.amazonaws</groupId>            <artifactId>aws-lambda-java-core</artifactId>            <version>1.2.0</version>        </dependency>        <dependency>            <groupId>pl.r6lab.aws</groupId>            <artifactId>rapid-dynamodb</artifactId>            <version>0.1.0</version>        </dependency>        <dependency>            <groupId>javax.json</groupId>            <artifactId>javax.json-api</artifactId>            <version>1.1.2</version>        </dependency>        <dependency>            <groupId>org.glassfish</groupId>            <artifactId>javax.json</artifactId>            <version>1.1.2</version>        </dependency>    </dependencies>

Example AWS Lambda handler that accepts request with uuid and after successful PutItem operation performs Scan and return all items:

publicclassRapidDynamoDBLambdaimplementsRequestHandler<Map<String,String>,String> {publicStringhandleRequest(Map<String,String>event,Contextcontext) {RapidDynamoDBClientrapidDynamoDBClient =RapidDynamoDBClient.envAware();DynamoDBRequestputItemRequest =DynamoDBRequest.of(Action.PUT_ITEM,getItemJson(event.get("uuid")));DynamoDBResponseresponse =rapidDynamoDBClient.execute(putItemRequest);if (response.isSuccess()) {DynamoDBRequestscanRequest =DynamoDBRequest.of(Action.SCAN,scanJson());returnrapidDynamoDBClient.execute(scanRequest).getPayload();        }else {context.getLogger().log(response.getPayload());thrownewIllegalStateException("Unable to put item into DynamoDB");        }    }privateStringgetItemJson(Stringuuid) {JsonObjectgetItemJson =Json.createObjectBuilder()                .add("TableName","Test")                .add("Item",Json.createObjectBuilder()                        .add("uuid",Json.createObjectBuilder()                                .add("S",uuid)))                .build();returngetItemJson.toString();    }privateStringscanJson() {JsonObjectgetItemJson =Json.createObjectBuilder()                .add("TableName","Test")                .add("ReturnConsumedCapacity","TOTAL")                .build();returngetItemJson.toString();    }}

About

Example lightweight DynamoDB integration that limits AWS Lambda cold starts for Java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp