Python 从sns发布到https端点的格式化消息

Python 从sns发布到https端点的格式化消息,python,aws-lambda,boto3,publish-subscribe,amazon-sns,Python,Aws Lambda,Boto3,Publish Subscribe,Amazon Sns,我正在向sns_主题发布消息,并起诉boto3。 我使用https端点作为协议。接收到端点的输出消息包含在“/”中。我试着通过这样做来逃避 def sns_publish(message, sns_event): try: topic_arn = get_topic_arn(sns_event) customer_id = str(message['customer_id']) message = json.dumps({&

我正在向sns_主题发布消息,并起诉boto3。 我使用https端点作为协议。接收到端点的输出消息包含在“/”中。我试着通过这样做来逃避

def sns_publish(message, sns_event):
    try:
        topic_arn = get_topic_arn(sns_event)        
        customer_id = str(message['customer_id'])
        message = json.dumps({"default":json.dumps(message)})
        sns_client.publish(TopicArn=topic_arn,
                            Message=message,
                           MessageStructure='json',
                           MessageAttributes={
                            'customer_id': {
                                'DataType': 'String',
                                'StringValue': customer_id
                            }})
    except Exception as e:
        logging.exception("SNSPublishError: {}".format(e))
接收到https端点的输出如下:

"Message": "{\"id\": \"WT3375104\", \"bill_to_nbr_x\": \"7159\", \"file_nbr_x\": \"3375104\"}"

我遵循boto3文档,在代码中给出了如上所示的消息和消息结构属性,如何从JSON输出中删除这些“/”aws的功能是以这种格式显示发送的数据,因此要使用JSON模块对其进行解析:

import json

mess = {"Message": "{\"id\": \"WT3375104\", \"bill_to_nbr_x\": \"7159\", \"file_nbr_x\": \"3375104\"}"}

print(json.loads(mess['Message']))
你试过使用吗?这将导致消息看起来不像SNS消息,这意味着该消息不需要转义,因为它不包含在另一个JSON对象中