Skip to content

Commit 5830ee1

Browse files
authored
fix(lambda): filterRule.null() returns empty array (#31701)
### Issue # (if applicable) Closes #31458. ### Reason for this change According to the documentation [here](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html#filtering-syntax), the FilterPattern should be [null]. However, the function FilterRule.null() currently returns an empty array [] instead. It results an invalid filter pattern definition. ### Description of changes Change the return value from `[]` to `[null]` ### Description of how you validated changes Add an integration test to validate the new return value. Also with the old return value, the deployment will fail with error `Invalid request provided: Invalid filter pattern definition.` so it should break existing customers. ### 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) **BREAKING CHANGE**: The function return value changes from `String[]` to `any` which could be a breaking change in some cases. However, the previous return value would fail the deployment hence it reduces the risk of breaking change. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7d6bf77 commit 5830ee1

11 files changed

+715
-3
lines changed

allowed-breaking-changes.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -932,4 +932,8 @@ removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_SWEDISH_FULL_BASE
932932
removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_TURKISH_FULL_BASE_2023_11_15
933933
removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_TURKISH_FULL_BASE_2023_12_13
934934
removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_TURKISH_FULL_BASE_2024_01_16
935-
removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_TURKISH_FULL_BASE_2024_02_14
935+
removed:aws-cdk-lib.aws_ec2.WindowsVersion.WINDOWS_SERVER_2022_TURKISH_FULL_BASE_2024_02_14
936+
937+
# null() return a [] which is invalid filter rule. It should return [null].
938+
# Hence the return type changes from string[] to any
939+
change-return-type:aws-cdk-lib.aws_lambda.FilterRule.null

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/FilterCriteriaNullDefaultTestDeployAssert51179964.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/FilterCriteriaNullDefaultTestDeployAssert51179964.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/lambda-event-source-filter-criteria-null.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"Resources": {
3+
"FuncServiceRole49680D06": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "lambda.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"FuncServiceRoleDefaultPolicy588DA782": {
35+
"Type": "AWS::IAM::Policy",
36+
"Properties": {
37+
"PolicyDocument": {
38+
"Statement": [
39+
{
40+
"Action": [
41+
"sqs:ChangeMessageVisibility",
42+
"sqs:DeleteMessage",
43+
"sqs:GetQueueAttributes",
44+
"sqs:GetQueueUrl",
45+
"sqs:ReceiveMessage"
46+
],
47+
"Effect": "Allow",
48+
"Resource": {
49+
"Fn::GetAtt": [
50+
"Queue4A7E3555",
51+
"Arn"
52+
]
53+
}
54+
}
55+
],
56+
"Version": "2012-10-17"
57+
},
58+
"PolicyName": "FuncServiceRoleDefaultPolicy588DA782",
59+
"Roles": [
60+
{
61+
"Ref": "FuncServiceRole49680D06"
62+
}
63+
]
64+
}
65+
},
66+
"Func217E03A4": {
67+
"Type": "AWS::Lambda::Function",
68+
"Properties": {
69+
"Code": {
70+
"ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}"
71+
},
72+
"Handler": "index.handler",
73+
"Role": {
74+
"Fn::GetAtt": [
75+
"FuncServiceRole49680D06",
76+
"Arn"
77+
]
78+
},
79+
"Runtime": "nodejs18.x"
80+
},
81+
"DependsOn": [
82+
"FuncServiceRoleDefaultPolicy588DA782",
83+
"FuncServiceRole49680D06"
84+
]
85+
},
86+
"FuncSqsEventSourcelambdaeventsourcefiltercriterianullQueueCEF92D9AD2F13C0B": {
87+
"Type": "AWS::Lambda::EventSourceMapping",
88+
"Properties": {
89+
"BatchSize": 5,
90+
"EventSourceArn": {
91+
"Fn::GetAtt": [
92+
"Queue4A7E3555",
93+
"Arn"
94+
]
95+
},
96+
"FilterCriteria": {
97+
"Filters": [
98+
{
99+
"Pattern": "{\"body\":{\"id\":[null]}}"
100+
}
101+
]
102+
},
103+
"FunctionName": {
104+
"Ref": "Func217E03A4"
105+
}
106+
}
107+
},
108+
"Queue4A7E3555": {
109+
"Type": "AWS::SQS::Queue",
110+
"UpdateReplacePolicy": "Delete",
111+
"DeletionPolicy": "Delete"
112+
}
113+
},
114+
"Parameters": {
115+
"BootstrapVersion": {
116+
"Type": "AWS::SSM::Parameter::Value<String>",
117+
"Default": "/cdk-bootstrap/hnb659fds/version",
118+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
119+
}
120+
},
121+
"Rules": {
122+
"CheckBootstrapVersion": {
123+
"Assertions": [
124+
{
125+
"Assert": {
126+
"Fn::Not": [
127+
{
128+
"Fn::Contains": [
129+
[
130+
"1",
131+
"2",
132+
"3",
133+
"4",
134+
"5"
135+
],
136+
{
137+
"Ref": "BootstrapVersion"
138+
}
139+
]
140+
}
141+
]
142+
},
143+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
144+
}
145+
]
146+
}
147+
}
148+
}

packages/@aws-cdk-testing/framework-integ/test/aws-lambda-event-sources/test/integ.sqs-null-filter.js.snapshot/manifest.json

+139
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)