Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toggle between transactional and promotional sms in amazon sns

TL;DR Wan't to specify transactional/promotional message type on the fly (as a param) without having to set the message attributes every time.

So I want to send OTPs to customer using amazon SNS and this is the code for the following:

import boto3

client = boto3.client('sns')
response = client.publish(
               PhoneNumber='some_phone_number',
               Message='some_message'
           )

According to their documentation, there are 2 message types:
1. Transactional (Time critical delivery)
2. Promotional (Non time critical delivery and cost effective)

I have an option to set the default message attributes using the set_sms_attributes() as follows:

client.set_sms_attributes(
           attributes={"DefaultSMSType": "Transactional" | "Promotional" }
)

I donot wan't to keep changing this param as they are defaults. I wan't to be able to specify the message type on the fly as a parameter in publish()

I checked out the MessageAttributes but according to their docs, it's not to specify the message type but contains metadata for the client to handle the message before processing it.

Is there a way to toggle the message type on the fly without having to set it in the default settings using the set_sms_attributes ?

like image 909
Adarsh Avatar asked Dec 31 '18 06:12

Adarsh


People also ask

Which AWS service can be used to send promotional text messages SMS to more than 200 countries worldwide?

With Amazon SNS, you can send SMS (text) messages to 200+ countries and for an expanded set of use-cases such as Multi-Factor Authentication (MFA) and One Time Passwords (OTP). Amazon SNS has no upfront costs and you can pay as you go.

What is the difference between Amazon SQS Simple queue Service and Amazon SNS Simple Notification Service )?

SNS is a pub/sub system, while SQS is a queueing system. You'd typically use SNS to send the same message to multiple consumers via topics. In comparison, in most scenarios, each message in an SQS queue is processed by only one consumer.

What is the format of structured notification messages sent by Amazon SNS?

The notification message sent by Amazon SNS for deliveries over HTTP, HTTPS, Email-JSON and SQS transport protocols will consist of a simple JSON object, which will include the following information: MessageId: A Universally Unique Identifier, unique for each notification published.


1 Answers

You can set it using 'AWS.SNS.SMS.SMSType' in the publish(). This attribute is described here, e.g.:

client = boto3.client('sns')
response = client.publish(
               PhoneNumber='some_phone_number',
               Message='some_message',
               MessageAttributes = {
                   'AWS.SNS.SMS.SMSType': {
                       'DataType': 'String',
                       'StringValue': 'Promotional'  # or 'Transactional'
                   }
               }
           )

Note: for some regions there is no cost difference between these 2 types.

like image 98
AChampion Avatar answered Oct 04 '22 00:10

AChampion