Skip to main content
  1. Posts/

Prevent AWS CLI V2 From Using Pager

·247 words·2 mins·
Ops AWS Automation

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:

#! /bin/bash

# If you pipe into something or assigne to a variable, it will be fine.
REGIONS=`aws ec2 describe-regions | jq '.Regions[].RegionName' -r`
for REGION in $REGIONS; do
  echo "Listing keypairs in $REGION..."
  aws --region $REGION ec2 describe-key-pairs
done

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. Add cli_pager= in ~/.aws/config file.

    [default]
    cli_pager=
    ...
    

    However, you have to add this option under all of your profiles.

  2. Set environment variable AWS_PAGER to 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.

W.T. Chang
Author
W.T. Chang

Related

Disable T3 Unlimited Using ASG Lifecycle Hooks, CloudWatch Events, and Lambda
·797 words·4 mins
Dev AWS EC2 Lambda CloudWatch Events Node.js Serverless Automation
The Long Way to Windows Container on Amazon EKS: Node Affinity
·616 words·3 mins
Ops Kubernetes AWS Container
The Long Way to Windows Container on Amazon EKS: VPC Resource Controller
·926 words·5 mins
Ops Kubernetes AWS Container