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

Pager preference is not obeyed on Windows #8351

Closed
jimbo8098 opened this issue Nov 22, 2023 · 7 comments
Closed

Pager preference is not obeyed on Windows #8351

jimbo8098 opened this issue Nov 22, 2023 · 7 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue pager issues related to AWS_PAGER, cli_pager, or other client-side paging (not API pagination) response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. windows

Comments

@jimbo8098
Copy link

Describe the bug

The AWS_PAGER environment variable or cli_pager config file parameter is not obeyed specifically if you wish to disable pagination. It is obeyed if you set it to a paginator of your choice.

Expected Behavior

Per the AWS CLI documentation you can set the AWS_PAGER environment variable to be a blank string (i.e. not $null) or you can set the relevant option in config like so:

cli_pager=

Both of these would not result in paginated output.

Current Behavior

> $Env:AWS_PAGER=$null
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'more' is not recognized as an internal or external command,
operable program or batch file.
> $Env:AWS_PAGER="less"
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'less' is not recognized as an internal or external command,
operable program or batch file.
> $Env:AWS_PAGER=""
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'more' is not recognized as an internal or external command,
operable program or batch file.
> [System.Environment]::SetEnvironmentVariable("AWS_PAGER","")
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'more' is not recognized as an internal or external command,
operable program or batch file.
> [System.Environment]::SetEnvironmentVariable("AWS_PAGER","less")
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'less' is not recognized as an internal or external command,
operable program or batch file.
> [System.Environment]::SetEnvironmentVariable("AWS_PAGER",$null)
> aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json
'more' is not recognized as an internal or external command,
operable program or batch file.

Note that if I instead run the AWS CLI command with --no-cli-pager, like below, the command works as expected:

aws ec2 describe-instances --filters "Name=tag:Name,Values=Workstation" --query Reservations[].Instances[] --output json --no-cli-pager

Reproduction Steps

  1. Set ~/.aws/config's default profile to have cli_pager=
  2. Open a new PowerShell Window
  3. Run [System.Environment]::SetEnvironmentVariable("AWS_PAGER","")
  4. Assume your AWS profile of choice. I used an existing SSO session by setting $Env:AWS_PROFILE to the relevant profile name.
  5. Run a CLI paginated AWS CLI command, such as the describe-instances command above. The output is be paginated.

Possible Solution

I use both Windows and Linux and haven't seen this same behaviour exhibited by Linux. I therefore suspect that this is just an oversight in how Windows handles variables.

Additional Information/Context

  • I don't set any AWS environment variables in my $PROFILE
  • I am using aws-cli/2.13.25 Python/3.11.5 Windows/10 exe/AMD64 prompt/off
  • I am using Powershell version 7.3.9

CLI version used

aws-cli/2.13.25 Python/3.11.5 Windows/10 exe/AMD64 prompt/off

Environment details (OS name and version, etc.)

Windows 10 Business 10.0.19045

@jimbo8098 jimbo8098 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2023
@tim-finnigan tim-finnigan added windows pager issues related to AWS_PAGER, cli_pager, or other client-side paging (not API pagination) labels Nov 24, 2023
@RyanFitzSimmonsAK RyanFitzSimmonsAK added p2 This is a standard priority issue investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-review This issue or pull request needs review from a core team member. and removed needs-triage This issue or PR still needs to be triaged. investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 27, 2023
@RyanFitzSimmonsAK
Copy link
Contributor

Hi @jimbo8098, thanks for reaching out. I'm still investigating this issue, but I wanted bring up that I think cli_pager = is actually working correctly. Your reproduction steps are setting both though, and from the environment variables docs, AWS_PAGER overrides cli_pager = .

I've been able to reproduce the issue with AWS_PAGER and am trying to root cause the problem.

@jimbo8098
Copy link
Author

My default Powershell profile .ps1 nor the default environment variables include a definition for AWS_PAGER. Here are the commands run in a newly opened Powershell window:

> echo "`"$Env:AWS_PAGER`""
""
> $Env:AWS_PAGER=""
> echo "`"$Env:AWS_PAGER`""
""
> $Env:AWS_PAGER="less"
> echo "`"$Env:AWS_PAGER`""
"less"

When cli_pager is not present in the AWS profile alongside $Env:AWS_PAGER set to "", paginated output is shown.

I suspect the environment variable is being interpreted incorrectly. Perhaps some oversight in how scopes in Windows might be different and the aspect of comparitors in Powershell specifically being a bit more advanced than a usual if[] block in Bash.

You have $Env:AWS_PAGER, sure, but you also have local scope with AWS_PAGER and also the machine level scope commonly set through setx or the environment variable dialog. Commonly, I'd expect that setting $Env:AWS_PAGER is most useful for a setting you wish to have persist temporarily for a Powershell terminal session, which is what I'd expect of this kind of definition. The cli_pager on the other hand would be a more persistent setting, remaining beyond just that session.

The presence of cli_pager= in the config file for the given profile works as expected. I was previously setting the default profile to use cli_pager= but this wasn't affecting the pagination but this is fine when set at a named profile scope. I had misread the documentation assuming this to set the default value for this which was incorrect.

@RyanFitzSimmonsAK RyanFitzSimmonsAK removed the needs-review This issue or pull request needs review from a core team member. label May 20, 2024
@kellertk
Copy link
Contributor

kellertk commented Sep 4, 2024

In PowerShell, and in Windows in general, empty string environment variables are poorly supported (with an exception, see below). Setting an environment variable to an empty string is interpreted by client tools as unsetting the variable.

That is,

C:\Users\tom>set AWS_PAGER=test

C:\Users\tom>set AWS_PAGER
AWS_PAGER=test

C:\Users\tom>set AWS_PAGER=

C:\Users\tom>echo %AWS_PAGER%
%AWS_PAGER%

C:\Users\tom>set AWS_PAGER
Environment variable AWS_PAGER not defined

Here we set the AWS_PAGER variable to test, read it back, then set it to and can't read it back anymore. This is because set interprets empty string as deleting the variable. PowerShell follows the same semantics:

~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.

~ ❯ $Env:AWS_PAGER="test"

~ ❯ ls env:/AWS_PAGER

Name                           Value
----                           -----
AWS_PAGER                      test

~ ❯ $Env:AWS_PAGER=""

~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.

There is a big difference between these shells though: cmd.exe will allow you to call set VARIABLE="" which sets %VARIABLE% to the literal string "", whereas PowerShell more intuitively interprets "" as null. That's also why using $null in PowerShell also unsets the variable. There are other API calls in Windows that you can use to set empty environment variables, but they are mostly undocumented and mostly unsupported.


An exception is a recent change to .NET 9, which does support empty environment variables. As of this message, .NET 9 is only in the Preview version of PowerShell.

PowerShell 7.5.0-preview.4
~ ❯ $Env:AWS_PAGER=$null

~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.

~ ❯ $Env:AWS_PAGER=""

~ ❯ ls env:/AWS_PAGER

Name                           Value
----                           -----
AWS_PAGER

Setting the environment variable this way, through a .NET 9 compatible client tool, does correctly disable the pager as documented.

@RyanFitzSimmonsAK RyanFitzSimmonsAK added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 4, 2024
@jimbo8098
Copy link
Author

jimbo8098 commented Sep 4, 2024 via email

@RyanFitzSimmonsAK
Copy link
Contributor

RyanFitzSimmonsAK commented Sep 4, 2024

The config file does work properly for paging operation output, but --no-cli-pager and the config file not working for help is a known issue.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 4, 2024
@RyanFitzSimmonsAK RyanFitzSimmonsAK added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 4, 2024
@jimbo8098
Copy link
Author

You're right @RyanFitzSimmonsAK , I'll close this issue now since the other issue is tracking it. I've already weighed in on that issue so hopefully it helps people piece together the solution!

Copy link

github-actions bot commented Sep 5, 2024

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.

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. p2 This is a standard priority issue pager issues related to AWS_PAGER, cli_pager, or other client-side paging (not API pagination) response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. windows
Projects
None yet
Development

No branches or pull requests

4 participants