We have a very simple use case where are python app sends SMS texts to on-call users when system alerts happen. I have created in AWS API acccess id/keys, and a toll-free number through Pinpoint.
My publish function looks like this:
try:
sns = boto3.client('sns',
aws_access_key_id='<our api id>',
aws_secret_access_key='<our api key>',
endpoint_url='https://sns-fips.us-east-2.amazonaws.com',
config=Config(region_name='us-east-2',
proxies={'https': '<our proxy>'}))
for o in users:
number = getattr(o,'number') if getattr(o,'number').startswith('+') else '+1' + getattr(o,'number').replace("-","").replace("(","").replace(")","")
print('Sending message ' + msg + ' to contact ' + getattr(o,'name') + ' at number ' + number)
result = sns.publish(PhoneNumber=number, Message=msg, MessageAttributes={'AWS.MM.SMS.OriginationNumber': {'DataType': 'String', 'StringValue': '+1<our tollfree>'}})
print(result)
except Exception as ex:
print("SMS API EXCEPTION: {0}".format(ex), flush=True)
If I don't include the MessageAttributes, the message sends just fine but gets the AWS assigned long number (which is going away soon). If I go into my SNS dashboard and manually send a message using our tollfree, it goes through. If change the toll free to something else, it doesn't go through. So I know the association is there.
I also tried changing the code to use the Boto pinpoint client and get the same behavior, no messaging occurs, no errors.
Using the sns publish, my results come back with a status code of 200, a request id, 0 retry attempts, etc. So it seems like the messages are being sent. And I see nothing in the SMS delivery logs.
Am I missing something here? Thanks in advance for any pointers.