Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bpauwels opened this issue Jul 2, 2024 · 4 comments · Fixed by #31011 · 4 remaining pull requests
Closed

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

bpauwels opened this issue Jul 2, 2024 · 4 comments · Fixed by #31011 · 4 remaining pull requests
Labels
@aws-cdk/aws-lambda-event-sources bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@bpauwels
Copy link

bpauwels commented Jul 2, 2024

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

@bpauwels bpauwels added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 2, 2024
@khushail khushail self-assigned this Jul 2, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. needs-reproduction This issue needs reproduction. labels Jul 2, 2024
@khushail
Copy link
Contributor

khushail commented Jul 8, 2024

Hi @bpauwels , thanks for reaching out. I checked the passage of boolean value and you seem to be correct in saying it does not accept Boolean values.
As can be seen in the code implementation, this function isEqual() accepts only string or numerical values.

public static isEqual(item: string | number): any {

@khushail khushail added p3 effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jul 8, 2024
@khushail khushail removed their assignment Jul 8, 2024
@OperationalFallacy
Copy link

What a luck, just tried to use filter for boolean and there is already a bug. 🍀

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2024
xazhao pushed a commit to xazhao/aws-cdk that referenced this issue Sep 12, 2024
…ws#31011)

### Issue # (if applicable)

Closes aws#30734 

### Reason for this change

Filtering on boolean values was not possible

### Description of changes

`lambda.FilterRule.isEqual(...)` now accepts `boolean` values

### Description of how you validated changes

Added a unit test and integration test

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.