Skip to content

lambda-eventsources: DynamoDB, unable to filter for bool values #30734

@bpauwels

Description

@bpauwels

Describe the bug

When I add a lambda-eventsource to a dynamodb stream, I cannot filter for bool values because the .isEqual() function only allows string parameters.

    // filter only items with someValue:true
    fn.addEventSource(new lambda_events.DynamoEventSource(tbl, {
      startingPosition: lambda.StartingPosition.LATEST,
      filters: [
        lambda.FilterCriteria.filter({
          eventName: lambda.FilterRule.isEqual('INSERT'),
          dynamodb: {
            NewImage: {
              'someValue': { BOOL: lambda.FilterRule.isEqual(true) } // this is not possible
            }
          }
        })
      ]
    }));

Expected Behavior

Possibility to filter for all DynamoDB data types.

Current Behavior

.isEqual() only takes string parameters

Reproduction Steps

    const tbl = new ddb.Table(this, 'T', {
      partitionKey: {
        name: 'id',
        type: ddb.AttributeType.STRING
      },
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      stream: ddb.StreamViewType.NEW_IMAGE
    });

    const fn = new lambda.Function(this, 'F', {
      runtime: lambda.Runtime.NODEJS_16_X,
      handler: 'index.handler',
      code: lambda.Code.fromInline(`exports.handler = function(event, context) {
        console.log(event);
        console.log(event.Records[0].dynamodb)
        return;
      }`),
    });

    // filter only items with someValue:true
    fn.addEventSource(new lambda_events.DynamoEventSource(tbl, {
      startingPosition: lambda.StartingPosition.LATEST,
      filters: [
        lambda.FilterCriteria.filter({
          eventName: lambda.FilterRule.isEqual('INSERT'),
          dynamodb: {
            NewImage: {
              'someValue': { BOOL: lambda.FilterRule.isEqual(true) }
            }
          }
        })
      ]
    }));

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.140.0

Framework Version

No response

Node.js Version

22.1.0

OS

MacOS 14.2.1

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions