Aws-cli: Parameter Validation Error using 'aws ec2 import-image'

Created on 21 Jan 2019  路  6Comments  路  Source: aws/aws-cli

Hi everybody,

I'm trying to use the vm import/export feature, the main objective is to pull .vmdk/vhdx from S3 to EC2, but I'm getting errors around the following flag:

--disk-containers
I'm following the official documentation provided here and here. I've checked the two version, inline option and json, but I'm getting errors.

aws ec2 import-image --description "Machine S" --license-type auto --disk-containers  containers.json  --dry-run 

Error parsing parameter '--disk-containers': Expected: '=', received: 'EOF' for input:
containers.json

the content of the json file is that I think is correct :

[
  {
    "Description": "Machine S",
    "Format": "vhdx",
    "UserBucket": {
        "S3Bucket": "migracion-devxxx",
        "S3Key": "File.vhdx"
    }
}
]

I don't know what exactly is the problem, if I run this using the --debug flag the exception starts here:

2019-01-21 15:31:46,944 - MainThread - awscli.argprocess - DEBUG - Parsing param --disk-containers as shorthand
2019-01-21 15:31:46,945 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/argprocess.py", line 331, in _parse_as_shorthand
    parsed = [self._parser.parse(v) for v in value]
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/argprocess.py", line 331, in <listcomp>
    parsed = [self._parser.parse(v) for v in value]
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/shorthand.py", line 146, in parse
    return self._parameter()
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/shorthand.py", line 151, in _parameter
    params.update(self._keyval())
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/shorthand.py", line 160, in _keyval
    self._expect('=', consume_whitespace=True)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/shorthand.py", line 316, in _expect
    'EOF', self._index)
awscli.shorthand.ShorthandParseError: Expected: '=', received: 'EOF' for input:
containers.json
               ^

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/clidriver.py", line 208, in main
    return command_table[parsed_args.command](remaining, parsed_args)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/clidriver.py", line 345, in __call__
    return command_table[parsed_args.operation](remaining, parsed_globals)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/clidriver.py", line 488, in __call__
    parsed_args, self.arg_table)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/clidriver.py", line 544, in _build_call_parameters
    arg_object.add_to_params(service_params, value)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/arguments.py", line 453, in add_to_params
    unpacked = self._unpack_argument(value)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/arguments.py", line 463, in _unpack_argument
    cli_argument=self, value=value)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/arguments.py", line 476, in _emit_first_response
    responses = self._emit(name, **kwargs)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/arguments.py", line 473, in _emit
    return self._event_emitter.emit(name, **kwargs)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/argprocess.py", line 314, in __call__
    cli_argument, value, service_name, operation_name)
  File "/snap/aws-cli/135/lib/python3.5/site-packages/awscli/argprocess.py", line 338, in _parse_as_shorthand
    raise ParamError(cli_argument.cli_name, str(e))
awscli.argprocess.ParamError: Error parsing parameter '--disk-containers': Expected: '=', received: 'EOF' for input:
containers.json
               ^
2019-01-21 15:31:46,946 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

Error parsing parameter '--disk-containers': Expected: '=', received: 'EOF' for input:
containers.json

documentation guidance service-api

Most helpful comment

@h3ct0rjs - Thank you for the feedback. I have submitting an internal ticket to our doc writers to review our documentation for improvements.

All 6 comments

Hi,
I was checking if the shorthand option will work, but I'm still getting two errors :disappointed:

aws ec2 import-image --description "Machine S" --license-type AWS --disk-containers Description="Machine S",Format="vhdx",UserBucket={S3Bucket="migracion-dev803",S3Key="PDI.vhdx"} --dry-run

Parameter validation failed:
Invalid type for parameter DiskContainers[0].UserBucket, value: S3Bucket=migracion-dev803, type: , valid types:
Invalid type for parameter DiskContainers[1].UserBucket, value: S3Key=PDI.vhdx, type: , valid types:

what's the proper way to write this part,I've checked multiple options UserBucket={S3Bucket="migracion-dev803",S3Key="PDI.vhdx"}

Hi everybody,

After checking the Parser code and trying to understand a little bit, I don't noticed the bug in the code. It seems like the documentation is not very clear, because trying multiple things I finally got the solution. Previously I execute :

aws ec2 import-image --description "Machine S" --license-type AWS --disk-containers Description="Machine S",Format="vhdx",UserBucket={S3Bucket="migracion-dev803",S3Key="PDI.vhdx"} --dry-run

which returns errors, I just notice that is necessary to add _" "_ in UserBucket="{}" but just after a few hours working on this.

aws ec2 import-image --description "Machine S" --license-type AWS --disk-containers Description="Machine S",Format="vhdx",UserBucket="{S3Bucket="migracion-dev803",S3Key="PDI.vhdx"}" --dry-run

If you know someone that can improve the docs it would be great to report this.

Thanks in advance,
sincerely,
H茅ctor F

@h3ct0rjs - Thank you for reaching out and providing all the helpful details. In your first response you indicated the following error:

Error parsing parameter '--disk-containers': Expected: '=', received: 'EOF' for input:
containers.json

This appears to be due to a syntax error where as --disk-containers containers.json should be written like --disk-containers file://containers.json. There are a few examples in our API documentation.

As to using the " " to resolve the next syntax issue, I wanted to point out additional documentation about CLI usage parameters as it reviews details as to when to use single or double quotes. "The Windows command prompt requires double quotation marks (" ") to enclose the JSON data structure. "

Please advise if this additional documentation clarify the usage questions.

hi @justnance I've verified what you tell me.

To fix this, I simply quote around the brackets like in the example command below.

$ aws ec2 import-image --description "BUS PDI" --license-type AWS --disk-containers Description="BUSPDI",Format="vhdx",UserBucket="{S3Bucket=migracion-dev803,S3Key=PDI.vhdx}" --dry-run

I've also provided the disk-containers as a JSON file instead of passing the parameters to the command individually. The command to use this file would then be:

$ aws ec2 import-image --description "BUS PDI" --license-type AWS --disk-containers file://containers.json --dry-run

I think tha you could improve your documentation, remarking the need of _"_ and file://

Thanks for the quick response.
I'm closing this issue.

@h3ct0rjs - Thank you for the feedback. I have submitting an internal ticket to our doc writers to review our documentation for improvements.

@justnance. Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings