Home > Enterprise >  Lambda event filtering for DynamoDB trigger
Lambda event filtering for DynamoDB trigger

Time:12-09

Here is a modified version of an Event type I am receiving in my handler for a lambda function with a DynamoDB someTableName table trigger that I logged using cargo lambda.

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 
        }
    ] 
}

Goal: Correctly filter with event_name=INSERT && valid=false

I have tried a number of options, for example; {"eventName": ["INSERT"]} While the filter is added correctly, it does not trigger the lambda on item inserted.

Q1) What am I doing incorrectly here?

Q2) Why is table_name returning None? The lambda function is created with a specific table name as trigger. The returned fields are returning an option (Some(_)) so I'm asssuming it returns None if the table name is specified on lambda creation, but seems odd to me?

Q3) From AWS Management Console > Lambda > ... > Trigger Detail, I see the following (which is slightly different from my code mentioned above), where does "key" come from and what does it represent in the original Event?

enter image description here

CodePudding user response:

Filters must follow the documented syntax for filtering in the Event Source Mapping between Lambda and DynamoDB Streams.

If you are entering the filter in the Lambda console:

{ "eventName": ["INSERT"], "dynamodb": { "NewImage": {"valid": { "BOOL" : [false]}} } }

CodePudding user response:

The attribute name is actually eventName, so your filter should look like this:

{"eventName": ["INSERT"]}
  • Related