EC2: every running instance on one line each
Instance ID, type, Name-tag, launch time, public IP — sortable, greppable, pastable. The morning check.
Setup
- → brew install awscli
- → aws configure
Cost per run
free
The one-liner
$ aws ec2 describe-instances \
--filters 'Name=instance-state-name,Values=running' \
| jq -r '.Reservations[].Instances[] |
[
.InstanceId,
.InstanceType,
((.Tags[]? | select(.Key=="Name") | .Value) // "-"),
.LaunchTime[0:19],
(.PublicIpAddress // "-")
] | @tsv' \
| column -t -s $'\t'What each stage does
- [01] aws
aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running'Filter server-side — much cheaper than fetching all and grepping. Other filter values: stopped, terminated, pending. - [02] jq
(.Tags[]? | select(.Key=="Name") | .Value) // "-"EC2 tags are an array of {Key,Value} objects, not a map. Pluck the 'Name' tag, fall back to '-' for unnamed instances. The `?` after `Tags[]` survives instances with no tags. - [03] jq
.LaunchTime[0:19]ISO timestamp truncated to YYYY-MM-DDTHH:MM:SS — drops the trailing `.000Z` for terminal readability. - [04] jq
@tsv | column -t -s $'\t'@tsv emits tab-separated fields; column aligns them. The classic JSON-to-aligned-table bridge.
Expected output (sample)
i-0abc123def4567890 t3.medium web-prod-1 2026-05-09T08:13:42 18.196.42.7 i-0xyz987uvw6543210 m5.large reprocess-worker 2026-05-10T14:22:11 - i-01230abcd5678efgh c6i.xlarge etl-batch 2026-05-08T11:05:33 3.122.18.91
Caveats & tips
- Add `--region eu-west-1` if your default region differs from where the instances live.
- To find idle candidates, pipe this list through `aws cloudwatch get-metric-statistics` for CPUUtilization.