1

Below is my customer table in DynamoDb

name: string

I have linked a trigger that would call Lambda function that in turn calls my app Endpoint which would do data transformation & save in SQL DB

Whenever I am adding any record or updating record in the above table, I can see that Lambda function is getting called. but not sure how can I capture the table data.

I need to capture the name value of the customer dynamoDb table via Lambda function which I can pass to my Endpoint.

Newbie to this. So please excuse if it's too simple. But couldn't find the info that could drive this for me.

Thanks!

2
  • You mean triggered by DynamoDB stream? Commented Apr 25, 2019 at 10:15
  • @jogold yes. correct Commented Apr 25, 2019 at 10:22

1 Answer 1

3

You Lambda function will receive a DynamoDB Streams Record Event (see Using AWS Lambda with Amazon DynamoDB for an example event).

You are going to map/loop over the Records key where you will find objects with eventName: INSERT. Inside the dynamodb key you will find the table data that you should process in your Lamdba function's code.

{
  "Records": [
    {
      "eventID": "1",
      "eventVersion": "1.0",
      "dynamodb": {
        "Keys": {
          "Id": {
            "N": "101"
          }
        },
        "NewImage": {
          "Message": {
            "S": "New item!"
          },
          "Id": {
            "N": "101"
          }
        },
        "StreamViewType": "NEW_AND_OLD_IMAGES",
        "SequenceNumber": "111",
        "SizeBytes": 26
      },
      "awsRegion": "us-west-2",
      "eventName": "INSERT",
      "eventSourceARN": eventsourcearn,
      "eventSource": "aws:dynamodb"
    }
  ]
}

In your case, the data should be located at Records[0].dynamodb.NewImage.name.S

If working with Node.js and mixed types in your table, I suggest using AWS.DynamoDB.Converter.unmarshall which converts a DynamoDB record into a JavaScript object. It allows you to do something like this:

const newImage = DynamoDB.Converter.unmarshall(event.Records[0].dynamodb.NewImage);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.