【问题标题】:Problem with Boto3 SNS SMS publish with OriginationNumber使用 OriginationNumber 发布 Boto3 SNS SMS 的问题
【发布时间】:2021-05-14 22:29:33
【问题描述】:

我们有一个非常简单的用例,当系统警报发生时,python 应用程序会向待命用户发送 SMS 文本。我在 AWS API 访问 id/keys 中创建了一个通过 Pinpoint 的免费电话号码。

我的发布功能如下所示:

        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)

如果我不包含 MessageAttributes,则消息发送得很好,但会获得 AWS 分配的长号码(很快就会消失)。如果我进入我的 SNS 仪表板并使用我们的免费电话手动发送一条消息,它就会通过。如果将免费电话更改为其他内容,则不会通过。所以我知道协会就在那里。

我还尝试更改代码以使用 Boto pinpoint 客户端并获得相同的行为,没有消息发生,没有错误。

使用 sns 发布,我的结果返回状态码 200、请求 id、0 次重试尝试等。所以看起来消息正在发送。而且我在 SMS 发送日志中什么也看不到。

我在这里遗漏了什么吗?提前感谢您的任何指点。

【问题讨论】:

    标签: boto3 amazon-sns aws-pinpoint


    【解决方案1】:

    哇,简单的解决方案。 Pinpoint 在east-2 中不可用,仅在east-1 中可用。切换区域,它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多