5
votes

During the aws configuration in CLI I use the command "aws configure", then i type the access key, secret access key, default region and default output type as "table".

What command i need to use in aws CLI to get the output in json format. For example if i use the command "aws ec2 describe-volumes --output json". Then it will give the output in JSON format only for this command. How to change Default output from table to json ?

2

2 Answers

11
votes

According to the documentation there are two ways to set the default output format

  1. Using the output option in a named profile in the config file. The following example sets the default output format to json.
[default]
output=json
  1. Using the AWS_DEFAULT_OUTPUT environment variable. The following output sets the format to json for the commands in this command-line session until the variable is changed or the session ends. Using this environment variable overrides any value set in the config file.
$ export AWS_DEFAULT_OUTPUT="json"

The first option will be the persistent one.

2
votes

The output format for AWS CLI is initially set while configuring the CLI using the command

aws configure

This command can be used again to change the output format permanently. Just press enter for the first three prompts (Access Key ID, Access Key and region name) and enter the desired output format in the last prompt and you're set.