# When no one at the client can say what runs in AWS, ask in SQL

> Steampipe needs only a read-only role to expose 589 AWS tables, though its cache means the numbers can be up to five minutes old.

Original: https://fdetimes.net/en/tools/steampipe-aws-inventory-sql/

The Hub page for Steampipe's AWS plugin lists 589 tables. They are AWS's APIs recast as tables, and you can ask all of them questions with `select`. Steampipe turns each query into API calls that run live against one or more cloud services.

For a forward deployed engineer, this matters most in the first week at a client. Before you can deploy anything, you need to know what the client already has: how many accounts, which regions are in use, where the resources sit. Usually nobody on the client's side can answer straight away, and the inventory on the internal wiki went stale long ago.

Steampipe lets you find the answers yourself in SQL, using a user or role with read-only permissions. Read access is usually far easier to obtain than write access to a client's infrastructure.

## Where does the data come from, and how long is it kept?

The Steampipe CLI runs queries on a bundled Postgres instance. According to the project's FAQ, the tool stores no data by default. A plugin calls the API, the results land in Postgres as temporary tables and are cached for only 5 minutes. The FAQ also says Steampipe is optimized for read-only queries.

Beyond the CLI, Steampipe also comes as a Postgres FDW, a SQLite extension, standalone export tools and Turbot Pipes, a cloud service. The source code lives at `github.com/turbot/steampipe` under the AGPL 3.0 license. The release marked Latest at the time of checking was v2.5.5.

When you talk to the client's security team, you can lean on two points the documentation states plainly: the tool is optimized for read-only queries, and by default results sit only in temporary tables with a 5-minute cache.

Be candid, though, that the CSV file you export for the handover is a lasting copy, and must be retained and deleted like any other client data.

## Three accounts, one SQL query

Take a hypothetical client with three AWS accounts, for production, staging and data, who wants to know how many virtual machines are running in each. The first job is getting permissions. The AWS plugin documentation says to attach the `ReadOnlyAccess` policy to the user or role Steampipe uses, so ask for exactly that policy.

The documentation also says each connection maps to one AWS account. So you declare three connections, then add an aggregator connection to combine them. According to the docs, an aggregator lets you query several connections of the same plugin as if they were a single connection. The `regions` parameter takes a list of regions and accepts wildcards.

```hcl
connection "aws_prod" {
  plugin  = "aws"
  profile = "prod"
  regions = ["*"]
}
# aws_staging and aws_data are declared the same way

connection "aws_all" {
  plugin      = "aws"
  type        = "aggregator"
  connections = ["aws_prod", "aws_staging", "aws_data"]
}
```

Naming the three connections explicitly tells anyone reading the configuration exactly which accounts the aggregator combines. After that, a single query does the job. Look up exact table names in the list of 589 tables on the Hub.

```sql
select account_id, region, count(*) as instance_count
from aws_all.aws_ec2_instance
group by account_id, region
order by instance_count desc;
```

The client will want to open the results in Excel, not read a terminal. The `--output` flag exports results as CSV or JSON. Steampipe's documentation also describes redirecting output to CSV as a common way to move data into tools such as Excel.

```bash
steampipe query inventory.sql --output csv > ec2-inventory.csv
```

## Is the number on screen the number right now?

Not necessarily, and this is a limit you must spell out to the client. The cache is on by default to speed up queries and cut the number of API calls, which helps avoid throttling. The price is that results may come from the cache. If the client has just shut down a cluster and asks again straight away, the figure you read out may be up to 5 minutes old.

Throttling is the second limit. A SQL query that sweeps every region across several accounts generates a great many API calls at once. Steampipe has client-side limiters that cap the rate and number of concurrent calls, reducing the risk of being blocked by the API server. When working on a client's production accounts, set a limiter first and only then run broad queries.

**Key point:** An inventory is only trustworthy if you can say when it was taken.

The third limit is legal. AGPL 3.0 is a license with strict conditions, so if the client plans to embed Steampipe in its own product, have the client's legal team read the license first.

## From inventory to security checks

Security checks and dashboards now live in a separate tool, Powerpipe. Steampipe v2.5.5 removed the `STEAMPIPE_DASHBOARD_START_TIMEOUT` environment variable because Steampipe never used it, as dashboards run in Powerpipe. If you come across older guides telling you to open dashboards inside Steampipe, treat them as out of date.

Powerpipe is also where the checks run. Turbot's AWS Compliance mod has more than 540 checks and supports many benchmarks, including CIS v4.0.0. You run it with `powerpipe benchmark run aws_compliance.benchmark.cis_v400`.

At a client, the sensible order is inventory first, benchmarks second. A table of resources by account and region shows the client you understand their system. A list of hundreds of compliance failures without context can easily turn the first meeting into a defensive one.

## What to learn first

Start with SQL. `group by`, `join` and filtering on JSON columns are what you will use most. Next comes the connection and aggregator model, because almost every client has more than one account. Then learn the cache and limiters, the two things that decide whether your numbers can be trusted and whether you disturb the client's production systems.

For your career, this skill is easy to demonstrate. On a CV, do not just write "knows Steampipe"; write the outcome: inventoried resources across multiple cloud accounts using read-only access and handed the client a CSV report. If an FDE job posting mentions working inside customers' cloud environments, that is the moment to bring up this example in the interview.

Clients rarely remember which SQL query you ran. What they remember is that in the first week you answered a question about their own infrastructure that their own people could not.

**Try this week:**

- Install Steampipe and run `steampipe plugin install aws` on a personal AWS account, using a role with only ReadOnlyAccess
- Create two connections and an aggregator, then write a SQL query that counts resources by account and region and export it with `--output csv`
- Run `powerpipe benchmark run aws_compliance.benchmark.cis_v400` on the test account, read the first three failures closely and write your own fix for each

## Sources

- [Steampipe: select * from cloud;](https://steampipe.io/blog/introducing-steampipe)

- [turbot/steampipe (GitHub README)](https://github.com/turbot/steampipe)

- [Release v2.5.5 · turbot/steampipe](https://github.com/turbot/steampipe/releases/tag/v2.5.5)

- [Steampipe README](https://raw.githubusercontent.com/turbot/steampipe/develop/README.md)

- [AWS plugin docs (docs/index.md), turbot/steampipe-plugin-aws](https://raw.githubusercontent.com/turbot/steampipe-plugin-aws/main/docs/index.md)

- [Steampipe Docs: Managing Connections](https://steampipe.io/docs/managing/connections)

- [AWS plugin | Steampipe Hub](https://hub.steampipe.io/plugins/turbot/aws)

- [Steampipe FAQ](https://steampipe.io/docs/faq/overview)

- [Users Guide to Steampipe Caching](https://steampipe.io/docs/guides/caching)

- [Users Guide to Concurrency & Rate Limiting](https://steampipe.io/docs/guides/limiter)

- [Steampipe Docs: Batch Queries](https://steampipe.io/docs/query/batch-query)

- [turbot/steampipe-mod-aws-compliance (GitHub README)](https://github.com/turbot/steampipe-mod-aws-compliance)
