AWS DynamoDB trigger using Lambda in JAVA

前端 未结 5 1829
天命终不由人
天命终不由人 2021-01-12 13:44

I am trying to trigger an AWS lambda function written in Java, on dynamodb stream events. Amazon has a guide for the same, using NodeJS here http://docs.aws.amazon.com/lambd

5条回答
  •  情书的邮戳
    2021-01-12 14:04

    This worked for me - case DynamoDB stream events:

    import com.amazonaws.services.lambda.runtime.RequestHandler;
    ...
    
    public class DynamoStreamHandler implements RequestHandler {
        @Override
        public Void handleRequest(Object o, Context context) {
    
            LinkedHashMap lhm = (LinkedHashMap) o;
            ...etc.
        }
    }
    

    It seems they use a customized JSON mapper which utilizes Map and List objects. It's quite straightforward (but tedious) to verify this for other event types by testing and print-outing logs. (sigh)

    EDIT: If ~5 MB overhead is ok, you can use DynamodbEvent.DynamodbStreamRecord provided by aws-lambda-java-events library v1.1.0 as described in AWS Lambda Walkthrough 3: Process Amazon DynamoDB Events (Java) in AWS Lambda Documentation.

提交回复
热议问题