Formatting DynamoDB data to normal JSON in AWS Lambda

前端 未结 8 1441
無奈伤痛
無奈伤痛 2020-12-01 02:55

I\'m using AWS Lambda to scan data from a DynamoDB table. This is what I get in return:

{
  \"videos\": [
    {
      \"fil         


        
8条回答
  •  时光说笑
    2020-12-01 03:34

    I know is a bit old but I had the same problem processing stream data from dynamoDB in node js lambda function. I used the proposed by @churro

    import sdk and output converter

    var AWS = require("aws-sdk");
    var parse = AWS.DynamoDB.Converter.output;
    

    use the parse function with a small hack

    exports.handler = function( event, context, callback ) {
      var docClient = new AWS.DynamoDB.DocumentClient();
      event.Records.forEach((record) => {
            console.log(record.eventID);
            console.log(record.eventName);
            console.log('DynamoDB Record:', parse({ "M": record.dynamodb.NewImage }));
        });
      callback(null, `Successfully processed ${event.Records.length} records.`);
    }
    

    Hope it helps

提交回复
热议问题