您需要为default
消息有效负载添加密钥,并指定MessageStructure
:
import json import boto3 message = {"foo": "bar"} client = boto3.client('sns') response = client.publish( TargetArn=arn, Message=json.dumps({'default': json.dumps(message)}), MessageStructure='json' )
以防您希望为短信和电子邮件订阅者提供不同的消息:
import json import boto3 message = {"foo": "bar"} client = boto3.client('sns') response = client.publish( TargetArn=arn, Message=json.dumps({'default': json.dumps(message), 'sms': 'here a short version of the message', 'email': 'here a longer version of the message'}), Subject='a short subject for your message', MessageStructure='json' )