aws / aws-cli

Universal Command Line Interface for Amazon Web Services
Other
15.09k stars 4.01k forks source link

ec2 subcommand fails when given --tag-specifications #8720

Open corey-cole opened 4 weeks ago

corey-cole commented 4 weeks ago

Describe the bug

This is a reopening of Issue #8211. Was able to verify that the behavior is present on multiple 2.x versions of the CLI across multiple operating systems.

Expected Behavior

AWS CLI commands should work when following the published documentation.

Current Behavior

AWS CLI command created following the published documentation fails with an unexpected error.

Reproduction Steps

# aws-cli/2.16.0 Python/3.11.9 Darwin/23.5.0 source/arm64
# Example from documentation with the only changes being specific VPC ID and CIDR block
aws ec2 create-subnet --vpc-id vpc-0d54e6a6aee42292c --cidr-block 10.21.16.0/20 --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-only-subnet}] --debug --region us-east-1
...
2024-06-04 14:02:12,031 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/clidriver.py", line 499, in main
    return command_table[parsed_args.command](remaining, parsed_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/clidriver.py", line 634, in __call__
    return command_table[parsed_args.operation](remaining, parsed_globals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/clidriver.py", line 837, in __call__
    return self._operation_caller.invoke(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/clidriver.py", line 963, in invoke
    response = self._make_client_call(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/clidriver.py", line 975, in _make_client_call
    response = getattr(client, xform_name(operation_name))(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/botocore/client.py", line 360, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/botocore/client.py", line 701, in _make_api_call
    request_dict = self._convert_to_request_dict(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/botocore/client.py", line 764, in _convert_to_request_dict
    request_dict = self._serializer.serialize_to_request(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/awscli/2.16.0/libexec/lib/python3.11/site-packages/awscli/botocore/validate.py", line 336, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter TagSpecifications[0].Tags[0], value: Key=Name, type: <class 'str'>, valid types: <class 'dict'>
Invalid type for parameter TagSpecifications[1].Tags[0], value: Value=my-ipv4-only-subnet, type: <class 'str'>, valid types: <class 'dict'>

Parameter validation failed:
Invalid type for parameter TagSpecifications[0].Tags[0], value: Key=Name, type: <class 'str'>, valid types: <class 'dict'>
Invalid type for parameter TagSpecifications[1].Tags[0], value: Value=my-ipv4-only-subnet, type: <class 'str'>, valid types: <class 'dict'>
# aws-cli/2.15.58 Python/3.11.8 Linux/6.1.90-99.173.amzn2023.x86_64 exec-env/CloudShell exe/x86_64.amzn.2023
aws ec2 create-subnet --vpc-id vpc-0d54e6a6aee42292c --cidr-block 10.21.16.0/20 --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-only-subnet}] --debug
...
2024-06-04 21:10:42,297 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
  File "awscli/clidriver.py", line 499, in main
  File "awscli/clidriver.py", line 634, in __call__
  File "awscli/clidriver.py", line 837, in __call__
  File "awscli/clidriver.py", line 963, in invoke
  File "awscli/clidriver.py", line 975, in _make_client_call
  File "awscli/botocore/client.py", line 360, in _api_call
  File "awscli/botocore/client.py", line 701, in _make_api_call
  File "awscli/botocore/client.py", line 764, in _convert_to_request_dict
  File "awscli/botocore/validate.py", line 336, in serialize_to_request
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter TagSpecifications[0].Tags[0], value: Key=Name, type: <class 'str'>, valid types: <class 'dict'>
Invalid type for parameter TagSpecifications[1].Tags[0], value: Value=my-ipv4-only-subnet, type: <class 'str'>, valid types: <class 'dict'>

Parameter validation failed:
Invalid type for parameter TagSpecifications[0].Tags[0], value: Key=Name, type: <class 'str'>, valid types: <class 'dict'>
Invalid type for parameter TagSpecifications[1].Tags[0], value: Value=my-ipv4-only-subnet, type: <class 'str'>, valid types: <class 'dict'>

Fully double quoting the argument to tag-specifications results in a successful invocation on both platforms.

Full debug log from MacOS is attached. debug-log-macos.txt

Possible Solution

No response

Additional Information/Context

No response

CLI version used

Multiple (see repro)

Environment details (OS name and version, etc.)

Multiple (see repro)

tim-finnigan commented 4 weeks ago

Thanks for reporting. Regarding the issue you referenced (https://github.com/aws/aws-cli/issues/8211) it looks like the example in the create-snapshots documentation has since been fixed to include quotes:

image

However there are not quotes in the example documented for create-subnet:

image

It looks like this relates to https://github.com/aws/aws-cli/issues/7227, where the takeaway was that this is an issue with how shorthand syntax examples are generated. So we may want to consolidate these issues. Also maybe further clarification regarding quoting could be added to the general documentation on shorthand syntax: https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-shorthand.html#shorthand-list-parameters