Prevent AWS CLI V2 From Using Pager
I always like to try new things out. So when I saw AWS CLI v2 is generally available, I just upgraded it without checking changes.
One thing I found different after the upgrade is that, seems all outputs are redirected to things like
less. It’s somehow inconvenient when calling AWS CLI in a shell script:
What happens at the line of
aws --region $REGION ec2 describe-key-pairs is that the script gets stuck in the screen of
less. It won’t proceed unless you hit q key.
The reason is mentioned in the document:
By default, AWS CLI version 2 returns all output through your operating system’s default pager program. By default this program is the less program on Linux and macOS, and the more program on Windows. This can make it easier for you to navigate a large amount of output from a service by displaying that output one page at a time.
And we have a few solutions:
1 2 3
[default] cli_pager= ...
However, you have to add this option under all of your profiles.
Set environment variable
AWS_PAGERto an empty string.
$ export AWS_PAGER=""
So, the lesson here? Don’t be lazy and read the document. Especially when it’s a major version upgrade.