How to put an Item in aws DynamoDb using aws Lambda with JAVA

时间:2015-11-12 10:38:39

标签: java amazon-web-services aws-lambda

I have created AWS Java Lambda project from ECLIPSE IDE. In the handle request section I want to process the request and insert it into a AWS DynamoDB table. In

I can see this can be easily done using node.js. Lot of code samples are available. Is there a proper JAVA help available. I am new to JAVA and struggling to find this. Any help is appreciated.

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaHandler implements RequestHandler<Object, Object> {
    @Override
    public Object handleRequest(Object input, Context context) {
        context.getLogger().log("Input: " + input);
        // TODO: implement DYNAMO DB INSERT
        return input;
    }

}

1 个答案:

答案 0 :(得分:1)

使用api in package com.amazonaws.services.dynamodbv2(maven dependency artifactID = aws-java-sdk-dynamodb)

AWSCredentials creds = new BasicAWSCredentials("myacceskey","mysecretkey");
AmazonDynamoDBClient dyndbclient = new AmazonDynamoDBClient(creds);
String tableName = "myDynamoDbTable"
Map<String, AttributeValue> dbItem = new HashMap<String, AttributeValue>();
//TODO put key/values from request in dbItem
dyndbclient.putItem(tableName, dbItem);

您可能还想重新定义lambda处理函数,以便获得比当前(对象输入)更好的强制转换输入参数