Nicolas
Nicolas

Reputation: 69

DynamoDB streams filter with nested fields not working

I have a Lambda hooked up to my DynamoDB stream. It is configured to trigger if both criteria are met:

My filter looks as follows:

{"eventName": ["MODIFY"], "dynamodb": {"NewImage": {"status": [{"numeric": [">", 10]}]}}}

If the filter is configured to only trigger if the event name is MODIFY it works, however anything more complicated than that does not trigger my Lambda. The event looks as follows:

{
    "eventID": "ba1cff0bb53fbd7605b7773fdb4320a8",
    "eventName": "MODIFY",
    "eventVersion": "1.1",
    "eventSource": "aws:dynamodb",
    "awsRegion": "us-east-1",
    "dynamodb":
    {
        "ApproximateCreationDateTime": 1643637766,
        "Keys":
        {
            "org":
            {
                "S": "test"
            },
            "id":
            {
                "S": "61f7ebff17afad170f98e046"
            }
        },
        "NewImage":
        {
            "status":
            {
                "N": "20"
            }
        }
    }
}

When using the test_event_pattern endpoint it confirms the filter is valid:

filter = {
    "eventName":  ["MODIFY"],
    "dynamodb": {
        "NewImage": {
            "status":  [ { "numeric": [ ">", 10 ] } ]
        }
    }
}

response = client.test_event_pattern(
    EventPattern=json.dumps(filter),
    Event="{\"id\": \"e00c66cb-fe7a-4fcc-81ad-58eb60f5d96b\", \"eventName\": \"MODIFY\", \"dynamodb\": {\"NewImage\":{\"status\": 20}}, \"detail-type\": \"myDetailType\", \"source\": \"com.mycompany.myapp\", \"account\": \"123456789012\", \"time\": \"2016-01-10T01:29:23Z\", \"region\": \"us-east-1\"}"
)
print(response) >> {'Result': True, 'ResponseMetadata': {'RequestId':...}

Is there something that I'm overlooking? Do DynamoDB filters not work on the actual new image?

Upvotes: 3

Views: 1072

Answers (2)

fefferoni
fefferoni

Reputation: 221

I realize I'm a bit late to the show, but for anyone else ending up here, DynamoDB event filtering doesn't support the use of numerical operators.

You can read more about it here.

Upvotes: 1

Jo.sch
Jo.sch

Reputation: 1

probably already found out yourself but for anyone else

its missing the dynamodb json specific numeric field leaf:

{
  "eventName": ["MODIFY"],
  "dynamodb": {
    "NewImage": {
      "status": { "N": [{ "numeric": [">", 10] }] }
    }
  }
}

Upvotes: 0

Related Questions