aws-cdk: aws-sns: When using filterPolicy, stack fails with: FilterPolicyScope: Invalid value [null]. Please use either MessageBody or MessageAttributes
Describe the bug
After updating cdk lib to 2.68.0, we are unable to deploy stacks that use SNS subscriptions with the filterPolicy parameter. Deployment errors out with
FilterPolicyScope: Invalid value [null]. Please use either MessageBody or MessageAttributes
Deployments were successful before resolving to the new version of the library. There is also no way to specify to use MessageAttributes in aws-cdk-lib/aws-sns-subscriptions or aws-cdk-lib/aws-sns lib.
Expected Behavior
The expected behavior is to successfully deploy the stack when using SqsSubscription with filterPolicy prop in v2.68.0 (or later) of aws-cdk-lib.
Current Behavior
The deployment errors out with:
FilterPolicyScope: Invalid value [null]. Please use either MessageBody or MessageAttributes (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: 42450475-089d-58ca-a91a-58eec215835a; Proxy: null)
In the cdk.out template, it indeed doesn’t have the scope param
"constructName": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "sqs",
"TopicArn": "---",
"Endpoint": {
"Fn::GetAtt": [
"----",
"Arn"
]
},
"FilterPolicy": {
"name": [
"myName"
]
},
"Region": "us-west-2"
},
"Metadata": {
"aws:cdk:path": "----"
}
}
Reproduction Steps
Here is how the constructs are set up. I can provide more details if needed.
import { SqsSubscription } from "aws-cdk-lib/aws-sns-subscriptions";
import { SubscriptionFilter } from "aws-cdk-lib/aws-sns";
....
const queue = new Queue(this, "myQueue", { queueName: queueName });
const topic = Topic.fromTopicArn(
this,
`myTopic`,
TOPIC_ARN,
);
topic.addSubscription(
new SqsSubscription(queue, {
filterPolicy: { name: SubscriptionFilter.stringFilter({ allowlist: ["myName"] }) },
}),
);
We tried completely rebuilding everything from scratch and cleaning npm but the stack still fails.
Possible Solution
Replace undefined with "MessageAttributes" here.
Additional Information/Context
No response
CDK CLI Version
2.68.0
Framework Version
No response
Node.js Version
16
OS
macOS 12.6
Language
Typescript
Language Version
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (6 by maintainers)
Yeah this has been fixed on the service side, closing but please do reopen if you see this again.
Encountered this today adding an SNS filter policy
@gerarar yeah in most cases it seems like removing a subscription and replacing it should be fairly safe anyway. That likely is the best workaround for now.