Hi, please let me know where to put DynamoDB strea...
# help
s
Hi, please let me know where to put DynamoDB stream FilterCriteria in SST. eg:
FilterCriteria: {
filters: [
{
pattern:
'{"eventName":["INSERT"],"dynamodb":{"pk":{"Type":{"S":["newsletter"]}}}}',
},
],
},
f
CDK has not yet added high level support for filter criteria https://github.com/aws/aws-cdk/issues/17874
But u can do something liek this to manually add it at the CloudFormation level:
Copy code
import { IConstruct } from "constructs";

function findEventSource(c: IConstruct): IConstruct | undefined {
  if (c.cfnResourceType === "AWS::Lambda::EventSourceMapping") {
    return c;
  }

  for (const child of c.node.children) {
    const found = findEventSource(child);
    if (found) {
      return found;
    }
  }
}

const eventSource = findEventSource(table);
eventSource?.addPropertyOverride("FilterCriteria", {
  Filters: [
    {
      Pattern: `{ \"eventName\": [\"INSERT\"], \"dynamodb\": { \"NewImage\": {\"channel\": { \"S\" : [\"email\"]}} } }`,
    },
  ],
});
It’s a bit ugly, u will be able to remove this once CDK adds support for it
a
Damn, if I had seen this, could have saved me 30 minutes 🙂
still, i learned something, so not completely wasted time