28

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?

tgal
  • 381
  • 1
  • 3
  • 4
  • What country is that phone number? – Piyush Patil Jul 13 '16 at 15:30
  • @error2007s Germany – tgal Jul 14 '16 at 16:34
  • I have the same trouble trying to send message from the console. No matter what i write in Sender ID field i got `NEXMO_SMS` instead. Is it a bug? – Diligent Key Presser Nov 11 '16 at 08:09
  • As workaround you can set 'DefaultSenderID' #!/usr/bin/env python import boto3 s = boto3.Session(profile_name='Godzilla') sns = s.client('sns') sns.set_sms_attributes( attributes={ 'DefaultSenderID': 'Godzilla', } ) response = sns.get_sms_attributes( attributes=[ 'DefaultSenderID', ] ) print(response) – tuxar Nov 30 '16 at 19:27

3 Answers3

7

The sender id must be 1-11 alpha-numeric characters, no spaces; for example:

  • THISISME - ✅
  • TestForSO - ✅
  • StackOverflow - (too long. max 11 chars)
  • Some one - (no spaces)

As others mentioned, the sender id customization depends on the country / cellular provider so make sure to test it.

Example snippet

import boto3

access_key = '....'
secret = '....'
region = "us-east-1"

number = '+972...<your number>'

sender_id = 'TestForSO'
sms_message = 'Your code: 123456'

sns = boto3.client('sns', aws_access_key_id=access_key, aws_secret_access_key=secret, region_name=region)
sns.publish(PhoneNumber=number, Message=sms_message, MessageAttributes={'AWS.SNS.SMS.SenderID': {'DataType': 'String', 'StringValue': sender_id}, 'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Promotional'}})

enter image description here

Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129
5

Check if your destination country supports sender IDs

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

Adam Owczarczyk
  • 2,802
  • 1
  • 16
  • 21
2

As noted by Adam Owczarczyk, some countries don't allow you to transmit a sender ID in a text message. The API will take your number and replace it with a string in this case to allow your message to get delivered. Attempting to work around it usually just gets the number blacklisted. You can test this by entering a short descriptive string for your tester ID, and seeing if that gets through.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
JaminaBee
  • 23
  • 5