aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Windows: "Structure option value must be JSON or path to file"

Open rosscar opened this issue 13 years ago • 18 comments

AWS CLI (version 0.8.0) does not appear to recognize JSON formatting when passing a key:value pair parameter for 'set-queue-attributes' when using AWS CLI under Windows. The same command works under Linux.

Steps to duplicate:

  1. Install AWS CLI on Windows
  2. Issue following @ Windows prompt: aws sqs set-queue-attributes --queue-url https://sqs.../MyQueueName --attributes '{"MaximumMessageSize":2048}'

rosscar avatar Mar 12 '13 00:03 rosscar

It can be made to work but it's not easy. Because there are embedded double-quotes within the option value, you must find a way to escape the string so the shell doesn't try to interpret the strings. In most Linux-type shells, you can escale the entire string by enclosing it in single-quotes. In Windows, however, it uses double-quotes as the escape character so you have to wrap the entire value in double-quotes and then escape individual embedded double-quotes with the backslash character, like this:

(testcli) C:\Users\Administrator\testcli>aws sqs set-queue-attributes
--queue-url https://us-west-2.queue.amazonaws.com/419278470775/foobar 
--attributes "{\"MaximumMessageSize\":\"2048\"}"

This is obviously tedious beyond words and we need to come up with something to help out here but until then, that is the workaround. Or, put the JSON values in a file and include that via the file: prefix.

garnaat avatar Mar 12 '13 02:03 garnaat

garnaat, thank-you for the clarification in regards to the needed escape characters. For now, I believe the best/easiest option is to use the file: prefix option - as you suggested. Here is how the command for that looks:

C:> aws sqs set-queue-attributes --queue-url https://sqs.../MyQueueName --attributes file:c:\pathtodirectory\maxmsgsize.json

The file, maxmsgsize.json, includes the following:

{"MaximumMessageSize":"2048"}

rosscar avatar Mar 12 '13 07:03 rosscar

Garnaat, I'm having a similar issue and I believe the solution is not as easy as I would have hoped. At least, I've spent hours searching and trying different combinations and I haven't been able to make the below work. Perhaps you can give some guidance?

I'm trying to run an instance with an additional mapped block device with PIOPS. I've got what I want finely tuned, but I still get an error about the json formatting.

Here's what I have and what I get:

aws ec2 run-instances --min-count 1 --image-id ami-xxxxxxxx --instance-type m2.4xlarge --block-device-mapping file:file.txt --max-count 1

Contents of file.txt:

{"DeviceName":"/dev/sdf",
"ebs":{
"VolumeSize":"1000",
"DeleteOnTermination":true,
"VolumeType":"io1",
"Iops":"1000"}}

Output is

Expecting property name: line 1 column 1 (char 1)

or sometimes it does parse well and then fail silently, starting an instance with the attached storage anyways. I have tried many iterations to solve this problem. This is just the latest attempt. Could you point me in the right direction? Region is us-west-2. I have the key and secret set an env variables

switch180 avatar Apr 02 '13 16:04 switch180

The help for run-instances shows this example for the --block-device-mapping option:

          Parameter Syntax

          [
            {
              "device_name": "string",
              "virtual_name": "string",
              "no_device": "string",
              "ebs": {
                {
                  "delete_on_termination": true|false,
                  "snapshot_id": "string",
                  "volume_size": integer,
                  "volume_type": "standard"|"io1",
                  "iops": integer
                }
            }
            ...
          ]

So, it is expecting a list of structures. Your file contains just a structure. Also, note the use of underscores rather than camelcase. I think if you change your file to look like this:

[{"device_name":"/dev/sdf",
  "ebs":{
      "volume_size":1000,
      "delete_on_termination":true,
      "volume_type":"io1",
     "iops":1000}}]

It should work

garnaat avatar Apr 02 '13 16:04 garnaat

Garnaat, That was it, man! Thank you so much. It worked as soon as I corrected it as recommended. I cant thank you enough.

switch180 avatar Apr 02 '13 17:04 switch180

You are very welcome. We are continuing to work on finding ways to give better error messages and to make the complex parameters easier to deal with. Suggestions are welcome!

garnaat avatar Apr 02 '13 17:04 garnaat

Here is an example starting a t1.micro with a root device of 20 Gb instead of 8 using command line and not file. Region is us-east.

~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --instance-type t1.micro --block-device-mapping '{"device_name":"/dev/sda1", "ebs":{"volume_size":20}}'

aquanyc avatar May 31 '13 02:05 aquanyc

How to do multiple devices on command line or in file ? I cannot get the list (using JSON array) to work for one device or multiple. While I have the command working for one device (see comment above) cannot do it for multiple devices. Region is US East. Thanks.

Single element in array: ~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --key-name histdata --instance-type t1.micro --block-device-mapping '{[{"device_name":"/dev/sda1", "ebs":{"volume_size":20}}]}'
Expecting property name: line 1 column 1 (char 1)

Multiple elements in array: ~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --key-name histdata --instance-type t1.micro --block-device-mapping ' { [{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10} } ] } ' Structure option value must be JSON or path to file.

aquanyc avatar May 31 '13 04:05 aquanyc

The --block-device-mapping should be a JSON list, so try removing the outer braces to the argument:

--block-device-mapping '[{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10} } ]'

Let me know if this doesn't work for you.

jamesls avatar May 31 '13 04:05 jamesls

Same result with outer braces removed:

~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --key-name histdata --instance-type t1.micro --block-device-mapping ' [{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10} } ] ' Structure option value must be JSON or path to file.

aquanyc avatar May 31 '13 04:05 aquanyc

Looks like we have a bug. You can't have any spaces between the opening ' and the [ character. Try this:

$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --key-name histdata --instance-type t1.micro --block-device-mapping '[{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10} } ] '

I've filed #136 to track this issue.

jamesls avatar May 31 '13 04:05 jamesls

Same error message...are you able to replicate ? Running command on ubuntu in us-east-1:

ubuntu@ip-10-152-188-90:~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --instance-type t1.micro --block-device-mapping '[{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10}}]' Structure option value must be JSON or path to file.

aquanyc avatar May 31 '13 17:05 aquanyc

I just did a copy/paste of the exact line above and did not get this error. I got a server error but that's only because I'm pointing to a different region than you are.

On Fri, May 31, 2013 at 10:30 AM, aquanyc [email protected] wrote:

Same error message...are you able to replicate ? Running command on ubuntu in us-east-1:

ubuntu@ip-10-152-188-90:~$ aws ec2 run-instances --image-id ami-5675ee3f --min-count 1 --max-count 1 --instance-type t1.micro --block-device-mapping '[{"device_name":"/dev/sda1", "ebs":{"volume_size":20} }, {"device_name":"/dev/xvdf", "ebs":{"volume_size":10}}]'

Structure option value must be JSON or path to file.

—

Reply to this email directly or view it on GitHubhttps://github.com/aws/aws-cli/issues/70#issuecomment-18759335 .

garnaat avatar May 31 '13 17:05 garnaat

Could it be a different version of the JSON parser?

brendandixon avatar May 31 '13 17:05 brendandixon

I needed to upgrade to latest version and it is now good.

If getting "Structure option value must be JSON or path to file" error, upgrade version with sudo easy_install --upgrade awscli

Thanks for help.

aquanyc avatar May 31 '13 17:05 aquanyc

While experimenting with JSON structure found repeating key:values just uses the last key:value...is this expected behaviour ? Ubuntu in region us-east-1.

This just adds one key Key:Value pair of two:d :

aws ec2 create-tags --resources i-3cb6ca4c --tag '{"key":"one","value":"b","key":"two", "value":"d"}' { "return": "true", "ResponseMetadata": { "RequestId": "9039472b-783c-48e8-87bc-dcac3b373bf4" }

aquanyc avatar May 31 '13 18:05 aquanyc

The structure for the --tag param is a list of key values pairs so it would be:

--tag '[{"key": "one", "value": "two"}, {"key": "two", "value": "two"}]'

As an alternative, if you're on the latest version (0.11.0 or greater) there's a shorthand syntax for this so you don't have to type json:

--tag key=one,value=two key=two,value=two

If you run aws ec2 create-tags help both of these formats will be documented with an example syntax:

       --tags (list)
              The tags to add or overwrite for the specified  resources.  Each
              tag item consists of a key-value pair.

       (structure)
              Represents metadata to associate with Amazon EC2 resources. Each
              tag consists of a user-defined key and value. Use tags to  cate-
              gorize EC2 resources, such as by purpose, owner, or environment.

       key (string)
              The tag's key.

       value (string)
              The tag's value.

              Shorthand Syntax

              As an alternative to JSON, you can specify this parameter as:

              Key value pairs, with multiple values separated by a space.

              --tags key=value,value=value

              JSON Parameter Syntax

              [
                {
                  "key": "string",
                  "value": "string"
                }
                ...
              ]

Let us know if you run into any other issues.

jamesls avatar May 31 '13 18:05 jamesls

Thanks and adding the shorthand syntax (--tag key=one,value=two,key=two,value=two) makes it a lot easier !!

aquanyc avatar May 31 '13 18:05 aquanyc