CloudQuery Platform
  • Introduction
    • Welcome to CloudQuery Platform
    • Getting Help
  • Quickstart
    • Creating a New Account
    • Platform Activation
  • Core Concepts
    • Integrations
    • Syncs
    • Filters & Queries
    • SQL Console
    • Reports
      • Built-in Report Templates
      • Reports Yaml Documentation with Examples
        • Full Report Example
  • Integration Guides
    • Setting up an AWS Integration
    • Setting up an AWS Cost and Usage Integration
    • Setting up a GCP Integration
    • Setting up an Azure Integration
    • Setting up a GitHub Integration
    • Setting up a K8s Integration
      • Using AWS EKS
      • Using Azure AKS
      • Using GCP GKE
    • General Integration Setup Guide
    • General Destination Setup Guide
  • Syncs
    • Setting up a Sync
    • Monitoring Sync Status
  • Cloud insights
    • From cloud asset inventory to insights
      • Security-focused queries
      • Compliance-focused queries
      • FinOps-focused queries
  • Production Deployment
    • Enabling Single Sign-on (SSO)
      • Single Sign-On with Google
      • Single Sign-On with Microsoft
      • Single Sign-On with Okta
  • User Management
    • Platform Roles Overview
    • Workspace Roles Overview
  • Advanced Topics
    • Custom Columns
    • Understanding Platform Views
    • Performance Tuning
  • Reference
    • Search & Filter Query Syntax
  • API Reference
  • CLI Docs
  • CloudQuery Hub
Powered by GitBook
On this page
  • Optimize cloud costs with SQL
  • FinOps queries in action
  • Want more?

Was this helpful?

  1. Cloud insights
  2. From cloud asset inventory to insights

FinOps-focused queries

Optimize cloud costs effortlessly with CloudQuery’s SQL-powered FinOps queries.

Optimize cloud costs with SQL

Managing cloud costs effectively requires real-time insights into resource usage and spending. CloudQuery allows you to run SQL queries on your cloud asset inventory, helping you identify cost inefficiencies and optimize expenses.

FinOps queries in action

Here are some essential queries to help you 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, name
Identify 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 types
Detect 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 days'; -- Older than 6 months

Want more?

These are just a few examples of how CloudQuery turns your cloud into an instantly queryable database—giving you unparalleled visibility into cost optimization opportunities.

PreviousCompliance-focused queriesNextEnabling Single Sign-on (SSO)

Last updated 2 months ago

Was this helpful?

Check out the for more ways to audit, secure, and optimize your cloud—all with SQL!

main query examples page