Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default output format in AWS CLI?

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 ?

like image 643
Armaan Avatar asked Apr 16 '19 10:04

Armaan


People also ask

What is default output format in AWS CLI?

JSON is the default output format of the AWS CLI. Most programming languages can easily decode JSON strings using built-in functions or with publicly available libraries.

What is default output format?

The Default output format specifies how the results are formatted. The value can be any of the values in the following list. If you don't specify an output format, json is used as the default. json – The output is formatted as a JSON string. yaml – The output is formatted as a YAML string.

How do I change my AWS CLI aws?

To switch between different AWS accounts, set the AWS_profile environment variable at the command line via export AWS_PROFILE=profile_name . Setting the env variable changes the default profile until the end of your shell session or until you set the variable to a different value.

Where is AWS CLI config?

Where are configuration settings stored? The AWS CLI stores sensitive credential information that you specify with aws configure in a local file named credentials , in a folder named . aws in your home directory.


2 Answers

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.

like image 122
Misantorp Avatar answered Sep 19 '22 12:09

Misantorp


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.

like image 27
Dheeraj Mohan Avatar answered Sep 20 '22 12:09

Dheeraj Mohan