Ross Coundon
12/18/2021, 6:40 PMFrank
Frank
Frank
Ross Coundon
12/18/2021, 6:57 PMFrank
Frank
Kujtim Hoxha
12/18/2021, 7:06 PMFrank
Kujtim Hoxha
12/18/2021, 7:07 PMFrank
import { CfnResource } from "@aws-cdk/core";
import { CfnEventSourceMapping } from "@aws-cdk/aws-lambda";
// Create table
const table = new sst.Table(this, "Table", {
  ...,
  stream: true,
  consumers: {
    consumerA: "src/lambda.main",
  },
});
// The "AWS::Lambda::EventSourceMapping" is created as a child construct of "AWS::Lambda::Function", let's find it
const eventSource = table.getFunction("consumerA")?.node.children.find(
  child => (child.node.defaultChild as CfnResource)?.cfnResourceType === "AWS::Lambda::EventSourceMapping"
);
// Add filter to the CFN resource directly
const cfnEventSource = eventSource?.node.defaultChild as CfnEventSourceMapping;
cfnEventSource?.addPropertyOverride("FilterCriteria", {"Filters": [{"Pattern": "{ \"body\" : { \"age\": [ { \"numeric\": [ \"=\", 27 ] } ]}}"}]})Frank
"FilterCriteria": {
          "Filters": [
            {
              "Pattern": "{ \"body\" : { \"age\": [ { \"numeric\": [ \"=\", 27 ] } ]}}"
            }
          ]
        }Ross Coundon
12/18/2021, 7:39 PMRoss Coundon
12/18/2021, 8:11 PMKevin Grimm
04/17/2022, 7:45 PMFilters: [
  {
    Pattern: JSON.stringify({
      dynamodb: {
        Keys: {
          PK: { 
            S: [
              { prefix: "PK-prefix" }
            ]
          },
          SK: {
            S: [
              { prefix: "SK-prefix" }
            ]
          },
        },
      },
    }),
  },
]Kevin Grimm
04/17/2022, 7:47 PM