skip to Main Content

I am trying to filter a DynamoDB stream via EventBridge patterns, I would like to be able to filter based on a value in specific column that can change for two reasons:

  1. A new row was inserted with the specific value I am looking for.
  2. An existing role’s value was changed to the desired value.

Any other changes should be ignored. I tried creating following filter:

{
  "eventName": ["INSERT", "MODIFY"],
  "dynamodb": {
    "NewImage": {
      "state": {
        "M": {
          "column": {
            "S": ["state1"]
          }
        }
      }
    },
    "OldImage": {
      "state": {
        "M": {
          "column": {
            "S": [{
              "anything-but": ["state1"]
            }]
          }
        }
      }
    }
  }
}

This of course fails because create operations do not have OldImage entries. Looking at the AWS documentation for conditional matches I then tried to add an $or statement with null and a valid OldImage entry but it it not considered to be a valid EventBridge:

"OldImage": {
 "$or" : [null, {....}]
}

Aside from simply creating a lambda that checks the OldImage vs the NewImage is there a way to achieve this via EventBridge filters?

2

Answers


  1. When you apply 2 filters together they become a Boolean AND expression. You want to acbibeia Boolean OR, so you should create 2 individual filters. You can attach up to 5 filters to a DynamoDB stream.

    Login or Signup to reply.
  2. I think this would work

    {"$or": [{
            "eventName": ["INSERT"],
            "dynamodb": {
                "NewImage": {
                    "state": {
                        "M": {
                            "column": {
                                "S": ["state1"]
                            }
                        }
                    }
                }
            }
        },
        {
            "eventName": ["MODIFY"],
            "dynamodb": {
                "NewImage": {
                    "state": {
                            "M": {
                                "column": {
                                    "S": ["state1"]
                                }
                            }
                        }
                    }
                },
                "OldImage": {
                    "state": {
                            "M": {
                                "column": {
                                    "S": [{"anything-but": ["state1"]}]
                                }
                        }
                    }
                }
            }
        ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search