How to publish message directly to a US phone number?

0

I have been using the boto3 sns client to publish messages to phone numbers and they are working for non US phone numbers but they do not work for US phone numbers. I have specified the origination numbers but they do not seem to be working.

sns_client = boto3.client("sns", region_name="us-west-2") try: response_sns = sns_client.publish( PhoneNumber=PhoneNo, Message="Hello," + first_name + ". Your OTP is " + str(OTP) + ".", MessageAttributes={ "AWS.SNS.SMS.SMSType": { "DataType": "String", "StringValue": "Transactional", }, "AWS.MM.SMS.OriginationNumber": { "DataType": "String", "StringValue": "+120******", }, }, ) print(response_sns) except Exception as e: print("could not send sms") print(e)

The use of US phone numbers doesnot show any errors. just that the messages are not received.

1 Answer
2

There are couple of things that you need to setup before getting this code worked and send message.

  1. Do you have Origination number setup(from SNS console), if not then you need to set that up first.
  2. Refer Adding and verifying phone numbers in the SMS sandbox and Origination numbers for more details. Once you have origination number set up, then you can test text messaging from SNS console first.
  3. Once you verify this through SNS console, your code should work as well.

I understand, API call doesn't give the error when you try to attempt to send message but if you'd try doing it through SNS, there you'll get error message as something like below:

Enter image description here

Hope this explains. Comment here if you have additional questions. Happy to help.

profile pictureAWS
EXPERT
answered 9 months ago
  • Do you have any query furthermore, happy to assist.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions