Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sns): Add FilterPolicyScope support #23108

Merged
merged 19 commits into from
Feb 24, 2023

Conversation

brennanho
Copy link
Contributor

@brennanho brennanho commented Nov 27, 2022


closes #23079

Description

This PR adds support for FilterPolicyScope for SNS subscriptions. This is in response to AWS introducing payload-based message filtering: https://aws.amazon.com/blogs/compute/introducing-payload-based-message-filtering-for-amazon-sns/.

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Nov 27, 2022

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Nov 27, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team November 27, 2022 21:04
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@brennanho brennanho changed the title feat(sns + sns-subscriptions): Add filterPolicyScope prop for sns subscriptions feat[sns + sns-subscriptions]: Add filterPolicyScope prop for sns subscriptions Nov 27, 2022
@brennanho brennanho changed the title feat[sns + sns-subscriptions]: Add filterPolicyScope prop for sns subscriptions feat(sns): Add filterPolicyScope prop for sns subscriptions Nov 27, 2022
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 28, 2022 03:45

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1 and removed p2 labels Nov 28, 2022
@peterwoodworth
Copy link
Contributor

Thanks for the PR for this feature @brennanho, This feature works and I'm able to deploy stacks with it, however we cannot manually add properties to the CfnSpec. We will need to wait until this property is defined in the specification, and then merged. This PR should be a great place to return to once we get L1 support, I'm going to convert this PR to a draft in the meantime

@peterwoodworth peterwoodworth marked this pull request as draft November 28, 2022 19:11
@wolfm89
Copy link

wolfm89 commented Dec 6, 2022

I think this PR is not sufficient to cover this: https://docs.aws.amazon.com/sns/latest/dg/subscription-filter-policy-constraints.html#subscription-filter-policy-payload-constraints

Amazon SNS accepts a nested filter policy for payload-based filtering.

This will still not be supported after merging this PR because the filter policy will not be parsable.

@brennanho
Copy link
Contributor Author

brennanho commented Dec 7, 2022

I think this PR is not sufficient to cover this: https://docs.aws.amazon.com/sns/latest/dg/subscription-filter-policy-constraints.html#subscription-filter-policy-payload-constraints

Amazon SNS accepts a nested filter policy for payload-based filtering.

This will still not be supported after merging this PR because the filter policy will not be parsable.

Ah thats interesting. I think some changes need to be made with how the Subscription class is creating the filterPolicy. I was thinking either having the key strings follow a dot notation e.g. {'key_a.key_b.key_c': sns.stringFilter({...})} OR passing in an object as how the keys appear e.g. {key_a: { key_b: { key_c: sns.stringFilter({...}) }}. The former would be easier to implement i believe but the latter would probably be a more intuitive / easier developer experience. Let me know what you think!

Edit:
Actually I tested it out locally and the parser seems to work fine with nested properties, I'll make sure to add some unit tests in the next commit though 👍 .

@wolfm89
Copy link

wolfm89 commented Dec 7, 2022

@brennanho I certainly would prefer the latter version {key_a: { key_b: { key_c: sns.stringFilter({...}) }} because it's closer to how the real filter would look like in the end.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@aws-cdk-automation aws-cdk-automation dismissed their stale review December 9, 2022 21:21

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@MrArnoldPalmer
Copy link
Contributor

Hey @brennanho, thanks for the update. I was working off the code you pushed as well and came up with this. I was misunderstanding the type of the top level input for the filterPolicyWithMessageBody prop as FilterOrPolicy, when I see it's required to be an object { [attribute: string]: FilterOrPolicy }. With that I think just using your buildFilterPolicyWithMessageBody as a free floating function does in fact make sense, where the bind pattern would work better if the top level type was FilterOrPolicy that could recursively build itself.

I also changed the body of buildFilterPolicyWithMessageBody, the important bit i using the isFilter or isPolicy methods to disambiguate the two more explicitly.

I also started going down the path of making buildFilterPolicyWithMessageBody return the totalCombinationValues alongside the built object so that we can make the type number instead of [number] in order to not have to use a reference and mutate the variable etc, but that's not that important and can be refactored later if we care to.

You don't have to take all these changes, but it does feel more simplified to me (closer to what you had originally before I made you complicate it 😄 ), but take what you think feels useful.

On the integ test, it's a little confusing but within the mono-repo, before the package is published, it just exists under the @aws-cdk/integ-tests package. You can add it to the package.json and run yarn install, which does linking of local dependencies where npm will not, since we use yarn workspaces. Checkout this appsync test for an example.

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Feb 23, 2023
Copy link
Contributor

@MrArnoldPalmer MrArnoldPalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brennanho! :shipit:

@mergify
Copy link
Contributor

mergify bot commented Feb 23, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed MrArnoldPalmer’s stale review February 23, 2023 20:31

Pull request has been modified.

@brennanho
Copy link
Contributor Author

@MrArnoldPalmer No problem and thanks for your help! Sorry I had to merge from main, do you think you could approve again please? 😄

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Feb 23, 2023
@mergify
Copy link
Contributor

mergify bot commented Feb 23, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@brennanho
Copy link
Contributor Author

brennanho commented Feb 24, 2023

@MrArnoldPalmer Looks like the automatic merge failed. I have the permissions enabled to update from main and all the previous checks passed. I have installed Mergify on my aws account and given it permissions for read/write. Looks like I still need to enable workflow permissions and some solutions online state I need to repush with a new PAT that includes workflow permissions. If that is the case I would need another approval (no code change). Unfortunately I am not seeing anything addressing this in the contribution guideline. Please advise thanks!

@brennanho
Copy link
Contributor Author

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2023

refresh

✅ Pull request refreshed

@mergify mergify bot dismissed MrArnoldPalmer’s stale review February 24, 2023 21:58

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 0489978
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit d986e14 into aws:main Feb 24, 2023
@brennanho brennanho deleted the add-filter-policy-scope branch February 24, 2023 23:38
@jkatnik
Copy link

jkatnik commented Feb 27, 2023

@brennanho could you please release this change? 🙏🏻

@brennanho
Copy link
Contributor Author

@brennanho could you please release this change? 🙏🏻

I think there are automatic chore releases done weekly. Like the following for example from last week 539d036. Correct me if I am wrong.

@MrArnoldPalmer
Copy link
Contributor

Yeah we release weekly usually, this will go out as part of the next release.

beck3905 pushed a commit to beck3905/aws-cdk that referenced this pull request Feb 28, 2023
----
closes aws#23079 

### Description
This PR adds support for FilterPolicyScope for SNS subscriptions. This is in response to AWS introducing payload-based message filtering: https://aws.amazon.com/blogs/compute/introducing-payload-based-message-filtering-for-amazon-sns/.

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@kzenia-1
Copy link

After this feature was released, we're unable to deploy stacks that use filterPolicy (not filterPolicyWithMessageBody).

I believe it's due to the following change where the FilterPolicyScope is undefined unless filterPolicyWithMessageBody is used.

The error we are getting:

Invalid parameter: FilterPolicyScope: Invalid value [null]. Please use either MessageBody or MessageAttributes

If I revert to the previous release (2.65.0), the stack successfully deploys.

@peterwoodworth
Copy link
Contributor

@Ksenia11 can you please create a new issue with a quick reproduction of how you've defined this construct?

@ksenia-exe
Copy link

@peterwoodworth done - issue.

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
----
closes aws#23079 

### Description
This PR adds support for FilterPolicyScope for SNS subscriptions. This is in response to AWS introducing payload-based message filtering: https://aws.amazon.com/blogs/compute/introducing-payload-based-message-filtering-for-amazon-sns/.

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@pabloizquierdoalegra
Copy link

pabloizquierdoalegra commented Jul 27, 2023

@brennanho Hi, I'm having a problem with this feature.

image

As you see on my screenshot, I'm creating a filter policy for a keyCountry attribute in the message body. But the result after deploying to aws is that the filter policy is set to Message Attributes instead of Message Body.

image

Any idea on why this could be happening?

@robpark
Copy link

robpark commented Jul 27, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1 pr/needs-cli-test-run This PR needs CLI tests run against it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SNS: payload-based message filtering