使用 AWS CLI 发布 SNS 消息(包括属性)

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

将消息发布到 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'
            }
        }
amazon-web-services command-line-interface aws-cli amazon-sns
1个回答
0
投票

您可以使用:

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"
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.