How to set the TTL attribute in the publish method of SNS in NodeJS?

Viewed 586

I'm writing code to send an OTP message. My current parameters and publish method look as follows:

params = {
  Message: otpMessage,
  MessageStructure: 'string',
  PhoneNumber: contactNo
};

sns.publish(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else console.log(data);           // successful response
});

How do I set the TTL attribute?

2 Answers

It appears you would like to set TTL attribute when sending OTP messages but currently Amazon SNS does not support setting TTL for any of the following :

  • SMS
  • SQS
  • HTTP
  • email.

TTL is only applicable when sending mobile push notification using any of the following platform :

  • APNS
  • APNS_Sandbox

  • FCM

  • ADM

  • Baidu

  • WNS

I set it up like this:

const params = {
    MessageStructure: 'json',
    Message: message,
    MessageAttributes: {
      'AWS.SNS.MOBILE.APNS.TTL': { DataType: 'Number', StringValue: '3600' },
      'AWS.SNS.MOBILE.FCM.TTL': { DataType: 'Number', StringValue: '3600' },
    },          
    TopicArn: topicArn
}
Related