简体   繁体   English

sqs 的 aws-cli 中 send-message 命令中消息属性的简写语法

[英]Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs

When trying to send a message using AWS CLI for SQS, I cannot get the shorthand syntax for the --message-attributes parameter to work.尝试使用适用于 SQS 的 AWS CLI 发送消息时,我无法使--message-attributes参数的简写语法起作用。

Specifying a json file works fine, and the reference doesn't show an example for the shorthand option.指定 json 文件可以正常工作,并且参考没有显示速记选项的示例。

Here is the reference for this command which specifies the shorthand I'm trying to use but I can't get it to work: http://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html这是此命令的参考,它指定了我正在尝试使用的速记,但我无法让它工作: http ://docs.aws.amazon.com/cli/latest/reference/sqs/send-message .html

Here's the command I've tried:这是我尝试过的命令:

aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name \
--message-body "message body goes here" \
--message-attributes firstAttribute={DataType=String,StringValue="hello world"},secondAttribute={DataType=String,StringValue="goodbye world"}

I keep getting error messages:我不断收到错误消息:

Parameter validation failed: Invalid type for parameter MessageAttributes.contentType, value: StringValue=Snapshot, type: , valid types:参数验证失败:参数 MessageAttributes.contentType 的类型无效,值:StringValue=Snapshot,类型:,有效类型:

Anyone ever managed sending attributes for message using the shorthand?有人曾经使用速记管理过消息的发送属性吗?

Currently, the documentation of the short-hand syntax for the --message-attributes option is incorrect and the short-hand syntax does not work.目前,-- --message-attributes选项的简写语法文档不正确,并且简写语法不起作用。

Instead, you can use the JSON file (as you mentioned).相反,您可以使用 JSON 文件(如您所述)。 You can also use the inline JSON:您还可以使用内联 JSON:

aws sqs send-message 
  --queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name 
  --message-body "message body goes here" 
  --message-attributes '{ "firstAttribute":{ "DataType":"String","StringValue":"hello world" }, "secondAttribute":{ "DataType":"String","StringValue":"goodbye world"} }'

Your Shorthand Syntax format is correct:您的速记语法格式是正确的:

MY_KEY ={DataType= String , StringValue= MY_VALUE } MY_KEY ={DataType= String , StringValue= MY_VALUE }

You just forgot to enclose the commandline option with single or double quotes:您只是忘记用单引号或双引号将命令行选项括起来:

aws sqs send-message \
  --queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name \
  --message-body "message body goes here" \
  --message-attributes 'firstAttribute={DataType=String, StringValue="hello world"}, secondAttribute={DataType=String,StringValue="goodbye world"}'

The above shortcut syntax should correctly produce a message with 2 extra headers, aka Message Attributes:上面的快捷语法应该正确地生成带有 2 个额外标头的消息,即消息属性:

firstAttribute=hello world
secondAttribute=goodbye world

NOTE:笔记:

an attribute is a <class 'dict'> , so every attribute looks like a dictionary: {DataType=String, StringValue=MY_VALUE} ,一个属性是一个<class 'dict'> ,所以每个属性看起来都像一个字典: {DataType=String, StringValue=MY_VALUE}

  • where supported DataType s are String , Number , or Binary .其中支持的DataTypeStringNumberBinary

  • each DataType value can contain an optional custom extention, that is ignored by AWS.每个 DataType 值都可以包含一个可选的自定义扩展,AWS 会忽略该扩展。 For example: String.uuid , Number.int , Binary.pdf .例如: String.uuidNumber.intBinary.pdf

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html#message-attribute-components https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html#message-attribute-components

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM