简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM