Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add SNS Filter Policy via Terraform

I have created an SNS topic and there are several other services subscribed to this topic to receive notifications.

Now, my requirement is to add a filter policy so that only the services that meet the requirement receive the message.

There is support for delivery_policy on terraform, but unable to use filter_policy on SNS.tf directly.

Please suggest if there is any alternative or correct me if my approach is wrong.

PS: I have to do this using terraform and not from AWS console

Thanks, Sumukha

like image 392
Sumukha Katta Prasanna Kumar Avatar asked Oct 29 '25 06:10

Sumukha Katta Prasanna Kumar


1 Answers

the filter needs to be applied to the subscriber and not the topic it self, let's assume the following config:

    resource "aws_sns_topic" "test" {
      name = "my-topic-with-policy"
    }

    resource "aws_sns_topic_subscription" "lambda_sns_subscription" {
      topic_arn = "${aws_sns_topic.test.arn}"
      protocol  = "lambda"
      endpoint  = "///"
      filter_policy = "${jsonencode(map("aa",list("aa")))}"
    }

see the filter_policy attribute on the "aws_sns_topic_subscription" resource

and then the fillter needs to be a valid json according to SNS Filter Doc: https://docs.aws.amazon.com/sns/latest/dg/sns-subscription-filter-policies.html

like image 87
Ilia Lazebnik Avatar answered Oct 31 '25 20:10

Ilia Lazebnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!