FinOps-Focused Queries
Reduce Cloud Costs with SQL
CloudQuery lets you query your cloud asset inventory to identify cost inefficiencies and reduce spending.
FinOps Queries in Action
Use these queries to cut costs and improve cloud efficiency.
Identify resources without a "cost center" tag (AWS, GCP, Azure)
Why it matters: Without a cost_center tag, it’s difficult to allocate cloud expenses correctly.
SELECT
cloud, account, name, region, resource_type, tags
FROM
cloud_assets
WHERE
tags NOT LIKE '%cost_center%';List unattached (orphaned) storage volumes (AWS, GCP, Azure)
Why it matters: Unused storage volumes drive up cloud costs unnecessarily.
WITH unattached_disks AS (
SELECT _cq_id FROM gcp_compute_disks WHERE length(users) = 0
UNION DISTINCT
SELECT _cq_id FROM azure_compute_disks WHERE managed_by is null
UNION DISTINCT
SELECT _cq_id FROM aws_ec2_ebs_volumes WHERE attachments='[]'
)
SELECT cloud, account, region, name, resource_type_label, tags
FROM cloud_assets a
JOIN unattached_disks d ON d._cq_id = a._cq_id
ORDER BY cloud, account, region, resource_type_label, nameIdentify expired reserved instances (AWS)
Why it matters: Missing out on renewing reserved instances leads to higher on-demand costs.
SELECT
arn, fixed_price, instance_count, instance_type
FROM
aws_ec2_reserved_instances
WHERE
toDate(end) < now();Find GCP BigQuery tables without partitioning enabled (GCP)
Why it matters: Tables without partitioning lead to expensive queries due to full table scans.
SELECT
friendly_name, project_id, location
FROM
gcp_bigquery_tables
WHERE
num_partitions = 0;List EC2 instances that are not using graviton processors (AWS)
Why it matters: Graviton-based instances provide better performance at a lower cost.
SELECT
arn, instance_type, region
FROM
aws_ec2_instances
WHERE
instance_type NOT LIKE 't4g%'
AND instance_type NOT LIKE 'm6g%'
AND instance_type NOT LIKE 'c6g%'
AND instance_type NOT LIKE 'r6g%'; -- List of Graviton-based instance typesDetect unused elastic IPs (AWS)
Why it matters: Unused Elastic IPs incur unnecessary costs.
SELECT
public_ip, instance_id
FROM
aws_ec2_eips
WHERE
instance_id IS NULL;List old snapshots that can be deleted (AWS)
Why it matters: Keeping old snapshots that are no longer needed increases storage costs.
SELECT
arn, allocated_storage, engine
FROM
aws_rds_db_snapshots
WHERE
instance_create_time < NOW() - INTERVAL 180 DAY; -- Older than 6 monthsMore query examples
See the query examples overview for security and compliance-focused queries.
Next Steps
- Security-Focused Queries - Security and compliance queries
- Compliance-Focused Queries - Compliance monitoring queries
- Reports - Build cost reports from your FinOps queries
- AWS CUR Integration - Add AWS billing data for cost analysis