kenta_desu
kenta_desu

Reputation: 383

Lambda event filtering for DynamoDB trigger

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

Upvotes: 2

Views: 2495

Answers (3)

Nagarjun Nagesh
Nagarjun Nagesh

Reputation: 81

A more complex filter criteria around the same theme could be entered via the AWS Console. {"awsRegion": ["eu-west-1"], "dynamodb": { "NewImage": {"stored_all_batched_content": { "BOOL" : [true]}},"StreamViewType": ["NEW_IMAGE"] },"eventName": ["MODIFY"], "eventSource": ["aws:dynamodb"]}

Upvotes: 0

fedonev
fedonev

Reputation: 25639

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

Upvotes: 4

Uri
Uri

Reputation: 141

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

{"eventName": ["INSERT"]}

Upvotes: 1

Related Questions