2

I am trying to use the aws Java API to create a lambda function that gets triggered on updates to a table in Dynamo DB. I was referring to tutorials in Amazon website (http://docs.aws.amazon.com/lambda/latest/dg/with-dynamodb-create-package.html). The code gets executed without issues but when i see the logs in cloudwatch,i see that the output(record.getDynamodb()) is not in JSON format. Whereas if i use node.js to create the lambda function, the output is in JSON format. Jusy trying to understand what needs to be done to get the output in JSON format. Plese help

public String handleRequest(DynamodbEvent ddbEvent, Context context) {
  for (DynamodbStreamRecord record: ddbEvent.getRecords()) {
    System.out.println(record.getDynamodb());
  }
}
Shibashis
  • 8,023
  • 3
  • 27
  • 38
Ashwin
  • 21
  • 4
  • Show the code please! – Failed Scientist Jun 05 '16 at 04:16
  • DynamodbStreamRecord is a java class, this is deserialized form of the JSON. You can always use an json libraries to convert it JSON, like ObjectMapper from Jackson, but it beats the purpose. Why would u want the JSON format – Shibashis Jun 05 '16 at 04:20
  • public String handleRequest(DynamodbEvent ddbEvent, Context context) { for (DynamodbStreamRecord record : ddbEvent.getRecords()) { System.out.println(record.getDynamodb()); } } – Ashwin Jun 05 '16 at 04:44
  • Hi Shibashis, Thanks for responding. I am trying to use the lambda function as a trigger to track changes to certain fields in Dynamo DB table. I have a scenario where i need to parse the old value and new value, find differences and do some processing. Please let me know if I am not clear. Thanks – Ashwin Jun 05 '16 at 04:49
  • Attaching the java method from amazon tutorials. Apologies for not formatting. Kindly let me know if you need anything else – Ashwin Jun 05 '16 at 04:53
  • See https://stackoverflow.com/questions/37655755/how-to-get-the-pure-json-string-from-dynamodb-stream-new-image/44308410#44308410 – Peter Jan 25 '19 at 14:22

0 Answers0