You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS CDK中KinesisEventSourceProps添加过滤规则后生成模板Filters为空数组问题求助

AWS CDK中KinesisEventSourceProps添加过滤规则后生成模板Filters为空数组问题求助

Hey there, sorry to hear you're stuck with this Kinesis filter issue in AWS CDK! Let's break down why your Filters section is ending up empty and how to fix it.

The root problem here is that you're using a raw Dictionary to define your filter pattern, but AWS CDK doesn't recognize this as a valid event source filter construct. When you pass an unrecognized type like that, CDK just ignores it, which is why your synthesized template shows an empty Filters array.

Instead, you need to use CDK's built-in classes specifically designed for event filters—this ensures your filter gets properly serialized into the CloudFormation template. Here's how to adjust your code to exclude events where Meta.Service is "NotKnown":

First, make sure you have these necessary imports at the top of your file:

using Amazon.CDK.AWS.Lambda;
using Amazon.CDK.AWS.Lambda.EventSources;

Then rewrite your filter setup like this:

// Create a filter pattern that excludes events with Meta.Service = "NotKnown"
var excludeNotKnownFilter = EventSourceFilter.Filter(
    FilterPattern.Not(
        FilterPattern.ObjectLike(new Dictionary<string, object>
        {
            { "Meta.Service", "NotKnown" }
        })
    )
);

// Assign the filter to your event source props
var sourceProps = new KinesisEventSourceProps
{
    Filters = new[] { excludeNotKnownFilter }
};

A few quick notes to keep in mind:

  • We use FilterPattern.Not() here because Lambda event filters are inclusive by default—this tells Lambda to skip any events that match the inner pattern (the ones you want to filter out).
  • The path Meta.Service matches the payload structure you shared ({ "Meta": { "Service": "NotKnown", ... } }). If your actual Kinesis records have the Meta object nested under another key (like the data key in your original code), just adjust the path to something like data.Meta.Service.
  • Using CDK's native filter constructs guarantees that your pattern is formatted correctly for CloudFormation during synthesis.

Give this code a try, and when you run cdk synth again, your template.json should finally show the proper Filters configuration instead of an empty array.

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 11:28:10