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

prints additional None with --output text, --query and --max-items

Open gonrial opened this issue 1 year ago • 3 comments

Describe the bug

Running a command with --max-items, --output text and --query produce an additional line with the string None. Any other combination does not show that string.

Also appeared as https://github.com/aws/aws-cli/issues/5654 and https://github.com/aws/aws-cli/issues/7172

@tim-finnigan sorry that I reopen this, but I didn't see the previous notifications. Now with debug data

Expected Behavior

arn:aws:ecs:<region>:<account>:task/<cluster>/<taskId>

Current Behavior

arn:aws:ecs:<region>:<account>:task/<cluster>/<taskId>
None <-----This is the extra string

Reproduction Steps

aws ecs list-tasks --cluster <cluster> --query 'taskArns' --output text --max-items 1

Where max-items should be n-1 elements from the existing tasks.

Possible Solution

No response

Additional Information/Context

Command with debug:

$ aws ecs list-tasks --cluster <cluster-name> --region <region> --desired-status 'RUNNING' --query 'taskArns' --output text --max-items 2 --debug

Result:

2022-09-15 21:02:18,984 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.7.21 Python/3.9.11 Linux/5.15.0-47-generic exe/x86_64.ubuntu.22
2022-09-15 21:02:18,984 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['ecs', 'list-tasks', '--cluster', '<cluster-name>', '--region', '<region>', '--desired-status', 'RUNNING', '--query', 'taskArns', '--output', 'text', '--max-items', '2', '--debug']
2022-09-15 21:02:19,009 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_s3 at 0x7febcb5ac550>
2022-09-15 21:02:19,009 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_ddb at 0x7febcb944040>
2022-09-15 21:02:19,009 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.configure.configure.ConfigureCommand'>>
2022-09-15 21:02:19,009 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x7febcb9e95e0>
2022-09-15 21:02:19,010 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function change_name at 0x7febcb9ee430>
2022-09-15 21:02:19,010 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function alias_opsworks_cm at 0x7febcb5b7ee0>
2022-09-15 21:02:19,010 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_history_commands at 0x7febcb90cb80>
2022-09-15 21:02:19,010 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <bound method BasicCommand.add_command of <class 'awscli.customizations.devcommands.CLIDevCommand'>>
2022-09-15 21:02:19,010 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler <function add_waiters at 0x7febcb5b7160>
2022-09-15 21:02:19,010 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.21/dist/awscli/data/cli.json
2022-09-15 21:02:19,015 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_types at 0x7febcb8b8e50>
2022-09-15 21:02:19,015 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function no_sign_request at 0x7febcb8bd9d0>
2022-09-15 21:02:19,016 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_verify_ssl at 0x7febcb8bd940>
2022-09-15 21:02:19,016 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_read_timeout at 0x7febcb8bdaf0>
2022-09-15 21:02:19,016 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <function resolve_cli_connect_timeout at 0x7febcb8bda60>
2022-09-15 21:02:19,016 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler <built-in method update of dict object at 0x7febcb4daf40>
2022-09-15 21:02:19,016 - MainThread - botocore.session - DEBUG - Setting config variable for region to '<region>'
2022-09-15 21:02:19,019 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.7.21 Python/3.9.11 Linux/5.15.0-47-generic exe/x86_64.ubuntu.22 prompt/off
2022-09-15 21:02:19,020 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['ecs', 'list-tasks', '--cluster', '<cluster-name>', '--region', '<region>', '--desired-status', 'RUNNING', '--query', 'taskArns', '--output', 'text', '--max-items', '2', '--debug']
2022-09-15 21:02:19,020 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_timestamp_parser at 0x7febcb5acb80>
2022-09-15 21:02:19,020 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function register_uri_param_handler at 0x7febcc09d310>
2022-09-15 21:02:19,020 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_binary_formatter at 0x7febcb51f430>
2022-09-15 21:02:19,021 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function no_pager_handler at 0x7febcc097670>
2022-09-15 21:02:19,021 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7febcbdd4160>
2022-09-15 21:02:19,022 - MainThread - botocore.utils - DEBUG - IMDS ENDPOINT: http://169.254.169.254/
2022-09-15 21:02:19,026 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function attach_history_handler at 0x7febcb90ca60>
2022-09-15 21:02:19,027 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_json_file_cache at 0x7febcb941e50>
2022-09-15 21:02:19,052 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.21/dist/awscli/botocore/data/ecs/2014-11-13/service-2.json
2022-09-15 21:02:19,074 - MainThread - botocore.hooks - DEBUG - Event building-command-table.ecs: calling handler <function inject_commands at 0x7febcb8b0700>
2022-09-15 21:02:19,074 - MainThread - botocore.hooks - DEBUG - Event building-command-table.ecs: calling handler <function add_waiters at 0x7febcb5b7160>
2022-09-15 21:02:19,100 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.21/dist/awscli/botocore/data/ecs/2014-11-13/waiters-2.json
2022-09-15 21:02:19,102 - MainThread - awscli.clidriver - DEBUG - OrderedDict([('cluster', <awscli.arguments.CLIArgument object at 0x7febcb047070>), ('container-instance', <awscli.arguments.CLIArgument object at 0x7febcb047040>), ('family', <awscli.arguments.CLIArgument object at 0x7febcb0470a0>), ('next-token', <awscli.arguments.CLIArgument object at 0x7febcb0470d0>), ('max-results', <awscli.arguments.CLIArgument object at 0x7febcb047160>), ('started-by', <awscli.arguments.CLIArgument object at 0x7febcb047130>), ('service-name', <awscli.arguments.CLIArgument object at 0x7febcb047100>), ('desired-status', <awscli.arguments.CLIArgument object at 0x7febcb047190>), ('launch-type', <awscli.arguments.CLIArgument object at 0x7febcb0471c0>)])
2022-09-15 21:02:19,103 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function add_streaming_output_arg at 0x7febcb5ace50>
2022-09-15 21:02:19,103 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function rename_arg.<locals>._rename_arg at 0x7febcb4cc280>
2022-09-15 21:02:19,103 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function add_cli_input_json at 0x7febcbdd4940>
2022-09-15 21:02:19,103 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function add_cli_input_yaml at 0x7febcbdd4b80>
2022-09-15 21:02:19,103 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function unify_paging_params at 0x7febcb944550>
2022-09-15 21:02:19,123 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.21/dist/awscli/botocore/data/ecs/2014-11-13/paginators-1.json
2022-09-15 21:02:19,124 - MainThread - awscli.customizations.paginate - DEBUG - Modifying paging parameters for operation: ListTasks
2022-09-15 21:02:19,125 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.ecs.list-tasks: calling handler <function add_generate_skeleton at 0x7febcb8b8430>
2022-09-15 21:02:19,126 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.ecs.list-tasks: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinput.CliInputJSONArgument object at 0x7febcb0472b0>>
2022-09-15 21:02:19,126 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.ecs.list-tasks: calling handler <bound method OverrideRequiredArgsArgument.override_required_args of <awscli.customizations.cliinput.CliInputYAMLArgument object at 0x7febcb0472e0>>
2022-09-15 21:02:19,126 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.ecs.list-tasks: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7febcb047460>>
2022-09-15 21:02:19,128 - MainThread - botocore.hooks - DEBUG - Event operation-args-parsed.ecs.list-tasks: calling handler functools.partial(<function check_should_enable_pagination at 0x7febcb944670>, ['next-token', 'max-results'], {}, OrderedDict([('cluster', <awscli.arguments.CLIArgument object at 0x7febcb047070>), ('container-instance', <awscli.arguments.CLIArgument object at 0x7febcb047040>), ('family', <awscli.arguments.CLIArgument object at 0x7febcb0470a0>), ('next-token', <awscli.arguments.CLIArgument object at 0x7febcb0470d0>), ('max-results', <awscli.arguments.CLIArgument object at 0x7febcb047160>), ('started-by', <awscli.arguments.CLIArgument object at 0x7febcb047130>), ('service-name', <awscli.arguments.CLIArgument object at 0x7febcb047100>), ('desired-status', <awscli.arguments.CLIArgument object at 0x7febcb047190>), ('launch-type', <awscli.arguments.CLIArgument object at 0x7febcb0471c0>), ('cli-input-json', <awscli.customizations.cliinput.CliInputJSONArgument object at 0x7febcb0472b0>), ('cli-input-yaml', <awscli.customizations.cliinput.CliInputYAMLArgument object at 0x7febcb0472e0>), ('starting-token', <awscli.customizations.paginate.PageArgument object at 0x7febcb047370>), ('page-size', <awscli.customizations.paginate.PageArgument object at 0x7febcb047580>), ('max-items', <awscli.customizations.paginate.PageArgument object at 0x7febcb047550>), ('generate-cli-skeleton', <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7febcb047460>)]))
2022-09-15 21:02:19,128 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.cluster: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,128 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.ecs.list-tasks: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7febcc041df0>
2022-09-15 21:02:19,129 - MainThread - awscli.arguments - DEBUG - Unpacked value of '<cluster-name>' for parameter "cluster": '<cluster-name>'
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.container-instance: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.family: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.next-token: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.max-results: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.started-by: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.service-name: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,129 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.desired-status: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.ecs.list-tasks: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7febcc041df0>
2022-09-15 21:02:19,130 - MainThread - awscli.arguments - DEBUG - Unpacked value of 'RUNNING' for parameter "desired_status": 'RUNNING'
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.launch-type: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.cli-input-json: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.cli-input-yaml: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.starting-token: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.page-size: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,130 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.max-items: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,131 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.ecs.list-tasks.generate-cli-skeleton: calling handler <awscli.paramfile.URIArgumentHandler object at 0x7febcb4a3a90>
2022-09-15 21:02:19,131 - MainThread - botocore.hooks - DEBUG - Event calling-command.ecs.list-tasks: calling handler <bound method CliInputArgument.add_to_call_parameters of <awscli.customizations.cliinput.CliInputJSONArgument object at 0x7febcb0472b0>>
2022-09-15 21:02:19,131 - MainThread - botocore.hooks - DEBUG - Event calling-command.ecs.list-tasks: calling handler <bound method CliInputArgument.add_to_call_parameters of <awscli.customizations.cliinput.CliInputYAMLArgument object at 0x7febcb0472e0>>
2022-09-15 21:02:19,131 - MainThread - botocore.hooks - DEBUG - Event calling-command.ecs.list-tasks: calling handler <bound method GenerateCliSkeletonArgument.generate_skeleton of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7febcb047460>>
2022-09-15 21:02:19,131 - MainThread - botocore.hooks - DEBUG - Event calling-command.ecs.list-tasks: calling handler functools.partial(<function check_should_enable_pagination_call_parameters at 0x7febcb944a60>, ['nextToken', 'maxResults'])
2022-09-15 21:02:19,132 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2022-09-15 21:02:19,132 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2022-09-15 21:02:19,132 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role-with-web-identity
2022-09-15 21:02:19,132 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: sso
2022-09-15 21:02:19,132 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2022-09-15 21:02:19,136 - MainThread - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials
2022-09-15 21:02:19,137 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/aws-cli/v2/2.7.21/dist/awscli/botocore/data/endpoints.json
2022-09-15 21:02:19,163 - MainThread - botocore.hooks - DEBUG - Event choose-service-name: calling handler <function handle_service_name_alias at 0x7febcd49d4c0>
2022-09-15 21:02:19,167 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.ecs: calling handler <function add_generate_presigned_url at 0x7febcd520ca0>
2022-09-15 21:02:19,172 - MainThread - botocore.endpoint - DEBUG - Setting ecs timeout as (60, 60)
2022-09-15 21:02:19,174 - MainThread - botocore.hooks - DEBUG - Event provide-client-params.ecs.ListTasks: calling handler <function base64_decode_input_blobs at 0x7febcb51fb80>
2022-09-15 21:02:19,174 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.ecs.ListTasks: calling handler <function generate_idempotent_uuid at 0x7febcd4b84c0>
2022-09-15 21:02:19,174 - MainThread - botocore.hooks - DEBUG - Event before-call.ecs.ListTasks: calling handler <function inject_api_version_header_if_needed at 0x7febcd4bbd30>
2022-09-15 21:02:19,174 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=ListTasks) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'X-Amz-Target': 'AmazonEC2ContainerServiceV20141113.ListTasks', 'Content-Type': 'application/x-amz-json-1.1', 'User-Agent': 'aws-cli/2.7.21 Python/3.9.11 Linux/5.15.0-47-generic exe/x86_64.ubuntu.22 prompt/off command/ecs.list-tasks'}, 'body': b'{"cluster": "<cluster-name>", "desiredStatus": "RUNNING"}', 'url': 'https://ecs.<region>.amazonaws.com/', 'context': {'client_region': '<region>', 'client_config': <botocore.config.Config object at 0x7febca4fe8e0>, 'has_streaming_input': False, 'auth_type': None}}
2022-09-15 21:02:19,175 - MainThread - botocore.hooks - DEBUG - Event request-created.ecs.ListTasks: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7febca4fe9d0>>
2022-09-15 21:02:19,175 - MainThread - botocore.hooks - DEBUG - Event choose-signer.ecs.ListTasks: calling handler <function set_operation_specific_signer at 0x7febcd4b83a0>
2022-09-15 21:02:19,175 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2022-09-15 21:02:19,175 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.1
host:ecs.<region>.amazonaws.com
x-amz-date:20220916T000219Z
x-amz-target:AmazonEC2ContainerServiceV20141113.ListTasks

content-type;host;x-amz-date;x-amz-target
c29bc000ee4edd55020110a0da52dc7ad788e34dec03ec6c0a5cd1c892d386e1
2022-09-15 21:02:19,175 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20220916T000219Z
20220916/<region>/ecs/aws4_request
7c9de7826d8357576616c9be6c5265ba62d55d1013da7cf99ec7527c2fa8045e
2022-09-15 21:02:19,176 - MainThread - botocore.auth - DEBUG - Signature:
f1b30a820bda24b7db2d41347f2ad3127f3e0e4491a07ee1b9f9e89fa54afcec
2022-09-15 21:02:19,176 - MainThread - botocore.endpoint - DEBUG - Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://ecs.<region>.amazonaws.com/, headers={'X-Amz-Target': b'AmazonEC2ContainerServiceV20141113.ListTasks', 'Content-Type': b'application/x-amz-json-1.1', 'User-Agent': b'aws-cli/2.7.21 Python/3.9.11 Linux/5.15.0-47-generic exe/x86_64.ubuntu.22 prompt/off command/ecs.list-tasks', 'X-Amz-Date': b'20220916T000219Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=AKIA01324567890/20220916/<region>/ecs/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=f1b30a820bda24b7db2d41347f2ad3127f3e0e4491a07ee1b9f9e89fa54afcec', 'Content-Length': '61'}>
2022-09-15 21:02:19,177 - MainThread - botocore.httpsession - DEBUG - Certificate path: /usr/local/aws-cli/v2/2.7.21/dist/awscli/botocore/cacert.pem
2022-09-15 21:02:19,179 - MainThread - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): ecs.<region>.amazonaws.com:443
2022-09-15 21:02:20,033 - MainThread - urllib3.connectionpool - DEBUG - https://ecs.<region>.amazonaws.com:443 "POST / HTTP/1.1" 200 484
2022-09-15 21:02:20,034 - MainThread - botocore.parsers - DEBUG - Response headers: {'x-amzn-RequestId': '49794795-5269-420e-9515-9533de73f1ad', 'Content-Type': 'application/x-amz-json-1.1', 'Content-Length': '484', 'Date': 'Fri, 16 Sep 2022 00:02:19 GMT'}
2022-09-15 21:02:20,034 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"taskArns":["arn:aws:ecs:<region>:<account-id>:task/<cluster-name>/<task-id-1>","arn:aws:ecs:<region>:<account-id>:task/<cluster-name>/<task-id-2>","arn:aws:ecs:<region>:<account-id>:task/<cluster-name>/<task-id-3>","arn:aws:ecs:<region>:<account-id>:task/<cluster-name>/<task-id-4>","arn:aws:ecs:<region>:<account-id>:task/<cluster-name>/<task-id-5>"]}'
2022-09-15 21:02:20,035 - MainThread - botocore.hooks - DEBUG - Event needs-retry.ecs.ListTasks: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x7febcad04460>>
2022-09-15 21:02:20,035 - MainThread - botocore.retries.standard - DEBUG - Not retrying request.
2022-09-15 21:02:20,036 - MainThread - botocore.hooks - DEBUG - Event after-call.ecs.ListTasks: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x7febca4fef10>>

CLI version used

aws-cli/2.7.21

Environment details (OS name and version, etc.)

Python/3.9.11 Linux/5.15.0-43-generic exe/x86_64.ubuntu.22 prompt/off

gonrial avatar Sep 16 '22 00:09 gonrial

Hi @gonrial, thanks for reaching out and sorry to hear you're having trouble.

I tried reproducing using the same command below on both v2.7.21 and v2.7.33 (latest version) and unfortunately I wasn't able to. I received expected output without additional line you mentioned. I would investigate more on your debug logs and sync up with tim-finnigan@ as well. Thanks for being patient with us!

 aws ecs list-tasks --cluster test-cluster --output text --query 'taskArns' --max-items 1

aBurmeseDev avatar Sep 18 '22 05:09 aBurmeseDev

@aBurmeseDev I give you a way to reproduce in a clean install.

Note that the cluster MUST have more items than the max-items parameter

docker run --rm -it -v $HOME/.aws:/root/.aws \
  --env AWS_PROFILE=<profile> \
  --env CLUSTER=<cluster> \
  ubuntu bash

apt-get update && apt-get install -yq curl unzip less

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install
aws --version

aws ecs list-tasks --cluster $CLUSTER --query 'taskArns' --output text # returns 5 elements
aws ecs list-tasks --cluster $CLUSTER --query 'taskArns' --output text --max-items 1

It is not only for ecs and task lists. Here is the same result for another resources

# aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text --max-items 2
i-01234567890     i-01234567890
None

gonrial avatar Sep 19 '22 12:09 gonrial

@gonrial - thank you for the clarification. I added more tasks in my cluster and can confirm that I was able to reproduce the same behavior.

I narrowed down the possible cause and the issue seems to be related to --output text. If you replace --output text with anything other than text format from the docs, there won't be additional line with None.

I also found out that you could use --no-paginate along with --output text to avoid the extra line as mentioned by a member here in similar issue.

aws ecs list-tasks --cluster test-cluster --query 'taskArns' --output text --no-paginate

Though, --no-paginate cannot be used along with --max-items in same command.

We're going to investigate further into this and keep this issue open while we do. Please feel free to check back in for further updates. Thank you again!

Best, John

aBurmeseDev avatar Sep 20 '22 22:09 aBurmeseDev

I'm experiencing a similar issue:

zvi.cahana:~/ $ aws ec2 describe-vpcs --filters Name=tag:Name,Values=k8s-tkg-0014-management-vpc --query "Vpcs[].VpcId" --max-items 1 --output text | cat
vpc-06071692433b1e83e
None
zvi.cahana:~/ $ aws ec2 describe-vpcs --filters Name=tag:Name,Values=k8s-tkg-0014-management-vpc --query "Vpcs[].VpcId" --max-items 2 --output text | cat
vpc-06071692433b1e83e	vpc-0b83a649f1e789bb8

Due to the ecs label on this issue, I'm highlighting that this isn't limited to ECS.

zcahana avatar Nov 02 '22 18:11 zcahana

Same for me with aws logs:

aws logs filter-log-events \
    --log-group-name log-group \
    --query 'events[0].message' \
    --output json
"/usr/local/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError"
aws logs filter-log-events \
    --log-group-name log-group \
    --query 'events[0].message' \
    --output text
/usr/local/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
None
None
aws logs filter-log-events \
    --log-group-name log-group \
    --query 'events[0].message' \
    --output text \
    --no-paginate
/usr/local/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError

Using AWS CLI v2.9.6.

krystof-k avatar Dec 18 '22 10:12 krystof-k

This appears to be intentional behavior:

Important

The output type you specify changes how the --query option operates:

  • If you specify --output text, the output is paginated before the --query filter is applied, and the AWS CLI runs the query once on each page of the output. Due to this, the query includes the first matching element on each page which can result in unexpected extra output. To additionally filter the output, you can use other command line tools such as head or tail.

  • If you specify --output json, --output yaml, or --output yaml-stream the output is completely processed as a single, native structure before the --query filter is applied. The AWS CLI runs the query only once against the entire structure, producing a filtered result that is then output.

https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html#cli-usage-filter-client-side

avx-rvandegrift avatar Jan 23 '23 20:01 avx-rvandegrift

Thanks for sharing the documentation in the comment above. As noted there, this is a limitation/edge case when using --output text and pagination. I recommend using --output json instead, or --output text | head -n 1.

tim-finnigan avatar Jun 24 '24 18:06 tim-finnigan

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jun 24 '24 18:06 github-actions[bot]