将消息发布到 SNS 主题时包含消息属性的正确语法是什么?我知道它是 --message-attributes,但是如何正确传递值?
例如,要发送消息,我使用此命令行:
aws sns publish --topic-arn "arn:aws:sns:us-east-1:09706xxxxxxx:UpdatesTopic" --message "Update 1"
我想包含这些消息属性:
MessageAttributes={
'type': {
'DataType': 'String',
'StringValue': 'event_type_a'
},
'srcArn': {
'DataType': 'String',
'StringValue': f'arn:aws:ec2:us-east-1:09706xxxxxxx:instance/instance_a'
},
'session_id': {
'DataType': 'String',
'StringValue': 'abc123'
},
'owner': {
'DataType': 'String',
'StringValue': 'me'
}
}
您可以使用:
aws sns publish --topic-arn "arn:aws:sns:us-east-1:09706xxxxxxx:UpdatesTopic" --message "hello" --message-attributes '{"type":{"DataType":"String","StringValue":"event_type_a"},"srcArn":{"DataType":"String","StringValue":"arnxxx"}}'
甚至:
aws sns publish --topic-arn "arn:aws:sns:us-east-1:09706xxxxxxx:UpdatesTopic" --message "hello" --message-attributes '
{
"type": {
"DataType": "String",
"StringValue": "event_type_a"
},
"srcArn": {
"DataType": "String",
"StringValue": "arnxxx"
}
}