Siddharth Sabron
Siddharth Sabron

Reputation: 1

Serverless Framework with TypeScript: Lambda Processing All DynamoDB Stream Events Despite Filters

I am using the Serverless Framework with TypeScript to process DynamoDB stream events and then publish them to an SNS topic. I have configured my Lambda function to use filters to process only specific events from the stream. However, the Lambda function is processing every event from the stream, including those that should be excluded by the filters.

Here is my current configuration:

{
            stream: {
                arn: "${self:provider.environment.SESSION_STREAM}",
                type: "dynamodb",
                filterPatterns: [
                    { eventName: ["INSERT", "UPDATE"] },
                    {
                      dynamodb: {
                        NewImage: {
                          status: {
                            S: ["COMPLETED"],
                          },
                        },
                      },
                    },
                    {
                      dynamodb: {
                        NewImage: {
                          order: {
                            M: {
                              amount: {
                                N: [{ exists: true }],
                              },
                            },
                          },
                        },
                      },
                    },
                  ],
                maximumRetryAttempts: 5,
                enabled: true,
                bisectBatchOnFunctionError: true
            }
        },

I have tried most of the links and can't find any TypeScript-based config or solution.

Upvotes: 0

Views: 69

Answers (1)

SAE
SAE

Reputation: 1739

I think, you expect all patterns to be applied - this is not the case.

From the documentation:

Your filters are logically ORed together. If a record from your event source satisfies one or more of your filters, Lambda includes the record in the next event it sends to your function. If none of your filters are satisfied, Lambda discards the record.

Your first pattern (eventName) will be satisfied for all events in the stream, so the other ones have no effect.

Upvotes: 0

Related Questions