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
?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With