How to send an SMS with custom sender ID with Amazon SNS and Python and boto3

tgal picture tgal · Jul 13, 2016 · Viewed 9.6k times · Source

The documentation suggests to use message attributes for that but I can't seem to figure out what attribute name to use.

This works so far:

sns = boto3.client('sns', region_name='eu-west-1')

sns.publish(
  PhoneNumber='+491701234567',
  Message='hi there',
  MessageAttributes={
    'AWS.SNS.SMS.SenderID': {
      'DataType': 'String',
      'StringValue': 'MySenderID'   
    }    
  }   
)  

The SMS is delivered but with some (random?) value in the sender id field. So it seems my setting of message attributes is silently ignored. What is the correct way to set a custom sender id?

Answer

Adam Owczarczyk picture Adam Owczarczyk · Apr 26, 2017

Check if your destination country supports sender IDs

http://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html