Lambda event filtering for DynamoDB - event_name INSERT not working

0

I have DynamoDB set as trigger for my lambda function and the following filter criteria, which is not working.

{"event_name": ["INSERT"]}

I've gone through some examples of properly written filters, but this fails to trigger the lambda. Furthermore, details of my lambda fn is as below. Enter image description here Where does "key" here come from and what does it represent in the Event I am passed to my handler? Here is what my Event looks like;

Event { 
    records: [
        EventRecord { 
            change: StreamRecord { 
                approximate_creation_date_time: ___ 
                keys: {"id": String("___")}, 
                new_image: {
                   ....
                    "valid": Boolean(true), 
                }, 
               ...
            }, 
            ...
            event_name: "INSERT", 
            event_source: Some("aws:dynamodb"), 
            table_name: None 
        }
    ] 
}

Other things bother me like seeing table_name blank because the trigger is specifically being called when data is changed in an specific, existing table.

asked a year ago1447 views
1 Answer
0
Accepted Answer

As you can here, the event that your Lambda receives is like this:

{
  "eventID": "c9fbe7d0261a5163fcb6940593e41797",
  "eventName": "INSERT",
  "eventVersion": "1.1",
  "eventSource": "aws:dynamodb",
  "awsRegion": "us-east-2",
  "dynamodb": {
    "ApproximateCreationDateTime": 1664559083.0,
    "Keys": {
      "SK": { "S": "PRODUCT#CHOCOLATE#DARK#1000" },
      "PK": { "S": "COMPANY#1000" }
    },
    "NewImage": {
      "quantity": { "N": "50" },
      "company_id": { "S": "1000" },
      "fabric": { "S": "Florida Chocolates" },
      "price": { "N": "15" },
      "stores": { "N": "5" },
      "product_id": { "S": "1000" },
      "SK": { "S": "PRODUCT#CHOCOLATE#DARK#1000" },
      "PK": { "S": "COMPANY#1000" },
      "state": { "S": "FL" },
      "type": { "S": "" }
    },
    "SequenceNumber": "700000000000888747038",
    "SizeBytes": 174,
    "StreamViewType": "NEW_AND_OLD_IMAGES"
  },
  "eventSourceARN": "arn:aws:dynamodb:us-east-2:111122223333:table/chocolate-table-StreamsSampleDDBTable-LUOI6UXQY7J1/stream/2022-09-30T17:05:53.209"
}

As you only want inserts, your filter pattern should look like this:

{ "eventName": ["INSERT"]}

In your case you specified event_name.

profile pictureAWS
EXPERT
Uri
answered a year ago
  • Thank you, I tried that earlier, but didn't work and changed it to event_name. BUT it is working now. Does it take some time to reflect the filter pattern?

    Also, I am making a second filter for valid in NewImage. Here is what I've tried; { "dynamodb": { "NewImage": { "valid": { "BOOL": [false] }}}} I've replaced BOOL with B, BOOLEAN, Bool, but none work so far.

    Based off of the scalarAttributeType enum, I'm guessing the correct choice is B, but not sure why it doesn't work.

  • Ok, it's flowing through now, I just needed a bit more patience. 5-10min for others who might find it useful.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions