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.

已提问 3 个月前199 查看次数
1 回答
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
专家
已回答 3 个月前
  • Do you have any query furthermore, happy to assist.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则