forked from markusklems/aws-lambda-java-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaFormFunctionHandler.java
More file actions
61 lines (53 loc) · 1.83 KB
/
Copy pathLambdaFormFunctionHandler.java
File metadata and controls
61 lines (53 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package lambda;
import java.util.HashMap;
import java.util.Map;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.PutItemRequest;
import com.amazonaws.services.dynamodbv2.model.PutItemResult;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
/**
*
* @author markusklems
*
*/
public class LambdaFormFunctionHandler implements
RequestHandler<Object, Object> {
private static AmazonDynamoDBClient dynamoDB;
/**
* Example object:
*
* {"employee_id":"1", "employee_name":"John Doh", "expense_type":"travel",
* "amount": "2565.75" }
*/
@Override
public Object handleRequest(Object input, Context context) {
dynamoDB = new AmazonDynamoDBClient().withRegion(Region
.getRegion(Regions.EU_WEST_1));
// TODO
// Parse the input object into a DynamoDB item, e.g., by using the newItem helper method
// Create a PutItemRequest and send the request at the DynamoDB table with name 'lambda-reimbursment'
return "{'status':'done'}";
}
/**
* Helper method.
*
* @param employee_id
* @param employee_name
* @param expense_type
* @param amount
* @return DynamoDB item
*/
private static Map<String, AttributeValue> newItem(String employee_id,
String employee_name, String expense_type, String amount) {
Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
item.put("employee_id", new AttributeValue((String) employee_id));
item.put("employee_name", new AttributeValue((String) employee_name));
item.put("expense_type", new AttributeValue((String) expense_type));
item.put("amount", new AttributeValue().withN(amount));
return item;
}
}