New! Filter and export controls, plus lots of new mods and plugins. →

Running Queries

The Steampipe interactive query shell is a great platform for exploring your data and developing queries, but Steampipe is more than just a query shell!

Non-interactive (batch) query mode

Steampipe allows you to run a query in batch mode and write the results to standard output (stdout). This is useful if you wish to redirect the output to a file, pipe to another command, or export data for use in other tools.

To run a query from the command line, specify the query as an argument to steampipe query:

steampipe query "select vpc_id, cidr_block,state from aws_vpc"

Query output formats

By default, the output format is table, which provides a tabular, human-readable view:

+-----------------------+---------------+-----------+
| vpc_id | cidr_block | state |
+-----------------------+---------------+-----------+
| vpc-0de60777fdfd2ebc7 | 10.66.8.0/22 | available |
| vpc-9d7ae1e7 | 172.31.0.0/16 | available |
| vpc-0bf2ca1f6a9319eea | 172.16.0.0/16 | available |
+-----------------------+---------------+-----------+

You can use the --output argument to output in a different format. To print your output to json, specify --output json:

$ steampipe query "select vpc_id, cidr_block,state from aws_vpc" --output json
[
{
"cidr_block": "10.66.8.0/22",
"state": "available",
"vpc_id": "vpc-0de60777fdfd2ebc7"
},
{
"cidr_block": "172.31.0.0/16",
"state": "available",
"vpc_id": "vpc-9d7ae1e7"
},
{
"cidr_block": "172.16.0.0/16",
"state": "available",
"vpc_id": "vpc-0bf2ca1f6a9319eea"
}
]

To print your output to csv, specify --output csv:

$ steampipe query "select vpc_id, cidr_block,state from aws_vpc" --output csv
vpc_id,cidr_block,state
vpc-0de60777fdfd2ebc7,10.66.8.0/22,available
vpc-9d7ae1e7,172.31.0.0/16,available
vpc-0bf2ca1f6a9319eea,172.16.0.0/16,available

Redirecting the output to CSV is common way to export data for use in other tools, such as Excel:

steampipe query "select vpc_id, cidr_block,state from aws_vpc" --output csv > vpcs.csv

To use a different delimiter, you can specify the --separator argument. For example, to print to a pipe-separated format:

$ steampipe query "select vpc_id, cidr_block,state from aws_vpc" --output csv --separator '|'
vpc_id|cidr_block|state
vpc-0bf2ca1f6a9319eea|172.16.0.0/16|available
vpc-9d7ae1e7|172.31.0.0/16|available
vpc-0de60777fdfd2ebc7|10.66.8.0/22|available