Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output text doesn't return same results as json output #9273

Closed
1 task
ShawnTuatara opened this issue Feb 4, 2025 · 2 comments
Closed
1 task

output text doesn't return same results as json output #9273

ShawnTuatara opened this issue Feb 4, 2025 · 2 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@ShawnTuatara
Copy link

Describe the bug

Wanting to get the first element in the list of CommandId based on the query I built. JSON output looks good initially and shows the two Ids. I add the | [0] to get the first element and that looks good with json output. Add --output text and the second id shows back up.

$ aws ssm list-commands --query "Commands[?starts_with(Comment,'Performance test')].CommandId" --filters "key=DocumentName,value=AWS-RunShellScript" "key=InvokedAfter,value=2025-01-01T00:00:00Z"
[
    "294cd794-d231-4d3f-9e2a-98a4594af415",
    "e31c41ce-6551-435e-ad89-eabe5fab2983"
]

$ aws ssm list-commands --query "Commands[?starts_with(Comment,'Performance test')].CommandId | [0]" --filters "key=DocumentName,value=AWS-RunShellScript" "key=InvokedAfter,value=2025-01-01T00:00:00Z"
"294cd794-d231-4d3f-9e2a-98a4594af415"

$ aws ssm list-commands --query "Commands[?starts_with(Comment,'Performance test')].CommandId | [0]" --filters "key=DocumentName,value=AWS-RunShellScript" "key=InvokedAfter,value=2025-01-01T00:00:00Z" --output text
294cd794-d231-4d3f-9e2a-98a4594af415
e31c41ce-6551-435e-ad89-eabe5fab2983

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The number of elements returned with text output matches the json output

Current Behavior

All elements are returned instead of only the first one

Reproduction Steps

Described in description.

Possible Solution

No response

Additional Information/Context

No response

CLI version used

2.17.29

Environment details (OS name and version, etc.)

aws-cli/2.17.29 Python/3.11.9 Linux/5.15.167.4-microsoft-standard-WSL2 exe/x86_64.ubuntu.24

@ShawnTuatara ShawnTuatara added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 4, 2025
@RyanFitzSimmonsAK RyanFitzSimmonsAK self-assigned this Feb 4, 2025
@RyanFitzSimmonsAK RyanFitzSimmonsAK added p3 This is a minor priority issue investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 4, 2025
@RyanFitzSimmonsAK
Copy link
Contributor

Hi @ShawnTuatara, thanks for reaching out. This is expected and documented behavior.

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, 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.

If you have fewer than 50 (the page size limit of SSM ListCommands) commands, you could get around this by setting --page-size 50. Otherwise, you'll need to further filter the output as the note described or use --output json. Let me know if you have any follow-up questions.

@RyanFitzSimmonsAK RyanFitzSimmonsAK added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Feb 4, 2025
Copy link

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants