如何在 Amazon SNS 中将 SMS 消息直接发布到美国的电话号码?

问题描述 投票:0回答:1

我一直在使用 boto3 SNS 客户端向电话号码发布消息,它们适用于非美国电话号码,但不适用于美国电话号码。我已经指定了原始号码,但它们似乎不起作用。

    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)

使用美国电话号码不会在 lambda 日志中显示任何错误。只是没有收到消息。

amazon-web-services aws-lambda amazon-sns
1个回答
0
投票

您需要修改发布方法的 MessageAttributes 参数,还需要将 AWS.MM.SMS.OriginationNumber 属性设置为在 Amazon SNS 中注册的有效美国电话号码。好吧,应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.