Smile Man
Smile Man

Reputation: 124

How to set message filtering on AWS SNS subscription using Javascript SDK

Using AWS SNS, I wanna set filter policy when I subscribe the sms endpoint to the topic. But I get this error : "Delivery protocol SMS does not support message filtering"

I will share the code here...

const AWS = require("aws-sdk")

module.exports.main = async (event) => {
    try {
      const sns = new AWS.SNS()
      const requestBody = event;
      var params = {
        Protocol: 'SMS', /* required */
        TopicArn: 'arn:aws:sns:us-east-1:XXXXXXXX:notification_system', /* required */
        Endpoint: requestBody.phoneNumber,
        Attributes: {
          "FilterPolicy": "{\`number`: [\`Filter1\`]}"
        }
      };
      var subscribePromise = await sns.subscribe(params).promise();

I am not sure why I am getting this error. I checked that I can set filter policy on AWS Console but not on sdk. Please help me to find out the solution. Thanks

Upvotes: 0

Views: 1480

Answers (1)

Smile Man
Smile Man

Reputation: 124

I am sorry, I found a solution. Protocol parameter should be lowercase "sms". The code should be like this.

const AWS = require("aws-sdk")

module.exports.main = async (event) => {
    try {
      const sns = new AWS.SNS()
      const requestBody = event;
      var params = {
        Protocol: 'sms', /* required */
        TopicArn: 'arn:aws:sns:us-east-1:XXXXXXXX:notification_system', /* required */
        Endpoint: requestBody.phoneNumber,
        Attributes: {
          "FilterPolicy": "{\`number`: [\`Filter1\`]}"
        }
      };
      var subscribePromise = await sns.subscribe(params).promise();

Upvotes: 1

Related Questions