3

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

  • eventName = "MODIFY"
  • status > 10

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?

Nicolas
  • 69
  • 9

1 Answers1

0

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

Jo.sch
  • 1
  • Doesn't work, at least not for me. Plugged your example in and the Lambda no longer triggered. The only way I can get it working is by specifically listing the numerical values. – Nicolas Mar 09 '23 at 15:10