aws-sns: When using filterPolicy, stack fails with: FilterPolicyScope: Invalid value [null]. Please use either MessageBody or MessageAttributes
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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](https://github.com/beck3905/aws-cdk/blob/main/packages/%40aws-cdk/aws-sns/lib/subscription.ts#L151).
### 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_
Contributor guide
Research direction
Start in packages/@aws-cdk/aws-sns/lib/subscription.ts at the linked subscription handling, then reproduce the SqsSubscription with filterPolicy from the issue. Check the synthesized AWS::SNS::Subscription template and deployment behavior; done means the template supplies a valid FilterPolicyScope and the stack deploys successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100