AWS stream and filter patterns - When value is not null

258 views Asked by At

I have a dynamodb and when one record is deleted, a lambda is called. My question is pretty simple as I'm interested only to those records that have a parameter different from null and it's weird but I wasn't able to find it anywhere neither in the official doc. It doesn't look like an edge case so I'm quite sure it's possible to do it.

Example, when a record is deleted the event is something like that:

{
  "Records": [
    {
      "eventName": "REMOVE",
      "dynamodb": {
        "Keys": { ... },
        "OldImage": {
          "pk": {
            "S": "mock_pk"
          },
          "address": {
            "NULL": true
          }
        }
      }
    }
  ]
}

My filter pattern instead:

{
  "eventName": ["REMOVE"],
  "dynamodb": {
    "OldImage": {
      "pk": {
        "S": [{ "prefix": "REG" }]
      },
      "address": {
        "S": [{ "anything-but": [null] }]
      }
    }
  }
}

But I've got this error:

Resource handler returned message: "Invalid request provided: Invalid filter pattern definition.

Seems like "anything-but" is not possible to use for this case and I rather not doing it in the code if there is the possibility.

1

There are 1 answers

1
Leeroy Hannigan On BEST ANSWER

There's a couple of issues at play here.

  1. First and foremost a String S cannot be null in DynamoDB, as DynamoDB maintains a separate Null bool: "NULL": true. So your request should not be anything-but, but instead exists, as you only want to know if the value exists as a String.

  2. The exception Resource handler returned message: "Invalid request provided: Invalid filter pattern definition is likely caused by a syntax error and not the use of anything-but.