AWS

Tutorials

Exploring the AWS Pricing API Using CloudQuery AWS Pricing Plugin

AWS Pricing is a publicly available API by AWS that lets you query pricing data for all AWS products and services. Here at CloudQuery, we simplified the process of retrieving this data to any database with our AWS Pricing Plugin.

Using this plugin, you can sync all the data available in the Pricing API to any destination available in our destination integrations. In the query examples below, we’ll use the PostgreSQL Destination Integration.

To begin, first download the CloudQuery CLI, and set up your CloudQuery configuration file by following the AWS Pricing Plugin docs. Then sync your data using our CLI:

cloudquery sync ./cloudquery-config

After completing a successful sync of the AWS pricing data to PostgreSQL, you will see three tables in your database. In this blog, we will focus on two of them: awspricing_service_products and awspricing_service_terms.

In the awspricing_service_products table, you get data about service and product configurations, like the instance type of an EC2 instance. In the awspricing_service_terms table, you get the pricing data, such as price per unit and method of pricing.

In both these tables, the interesting data is in a JSON column. For awspricing_service_products, it's the attributes column.

SELECT
sku,
product_family,
attributes,
attributes->>'instanceType' as instance_type,
attributes->>'servicename' as service_name,
attributes->>'regionCode' as region
FROM awspricing_service_products
WHERE product_family = 'Compute Instance'

In this example, you queried all the Compute Instance data and extracted the instance type, service name, and region from the attributes column (more properties like memory and vCPU are available for compute instances, and many other properties are available for other product families).

To add the pricing data for each of these options, you can join the awspricing_service_terms table using the column SKU, which is a unique identifier for a product (service code), usage type, and operation for an AWS resource.

WITH expanded_price_dimensions AS (
SELECT
st.sku,
st.type,
st.effective_date,
jsonb_array_elements(st.price_dimensions) AS price_dimension
FROM
awspricing_service_terms AS st
)
SELECT
sp.sku,
sp.product_family,
sp.attributes->>'regionCode' AS region,
sp.attributes->>'instanceType' AS instance_type,
epd.effective_date,
epd.price_dimension->'pricePerUnit'->>'USD' AS price_per_unit_usd,
epd.price_dimension->>'description' AS price_description,
epd.price_dimension->>'unit' AS unit
FROM
awspricing_service_products AS sp
JOIN
expanded_price_dimensions AS epd
ON
sp.sku = epd.sku
WHERE
sp.attributes->>'servicecode' = 'AmazonEC2'
AND epd.type = 'OnDemand';

Which would result in a table similar to this:

skuproduct_familyregioninstance_typeeffective_dateprice_per_unit_usdprice_descriptionunit
EJ5QZDS2Q5TZUCNPCompute Instance (bare metal)me-south-1g4dn.metal2024-06-019.7210000000$9.721 per Unused Reservation SUSE g4dn.metal instanceHrs
ENA7E6VASMYE9AEWCompute Instanceca-central-1g4dn.4xlarge2024-06-010.0000000000$0.00 per Dedicated Reservation SUSE g4dn.4xlarge instanceHrs
VHGKKHY2K6TR9AFJCompute Instanceap-northeast-2r5ad.2xlarge2024-06-010.8000000000$0.80 per Dedicated RHEL r5ad.2xlarge InstanceHrs
36JTR2DQPBVQ3RPXCompute Instanceap-northeast-2i4i.8xlarge2024-06-010.0000000000$0.00 per Reservation Windows with SQL Server i4i.8xlarge instanceHrs
NJW5JWT9Z8TAHHBXCompute Instance (bare metal)me-south-1r5.metal2024-06-0119.0950000000$19.095 per Unused Reservation RHEL with SQL Server r5.metal instanceHrs

And if you remove the sp.attributes->>'servicecode' = 'AmazonEC2' filter, you will see results similar to this:

skuproduct_familyregioninstance_typeeffective_dateprice_per_unit_usdprice_descriptionunit
ZMZHSJSJK564HSMUDirect Connectus-east-2None2024-05-011.6500000000$1.65 per connected HC-5G port-hour (or partial hour)hours
QBEEWE4UKYRAM42XCompute Instanceap-northeast-2m5.4xlarge2024-06-010.9720000000$0.972 per Unused Reservation Ubuntu Pro m5.4xlarge instanceHrs
VEFTTRHQSPAV5GNData TransferNoneNone2024-06-010.0000000000$0.00 per GB – US West (Verizon) data transferGB
866YX28WTJXGZUE4Compute Instanceap-northeast-2r6i.large2024-06-010.4672000000$0.4672 per Dedicated RHEL with SQL Standard r6i.large instanceHrs
4FY48AB87PFP3CQGuardDutyca-west-1None2024-05-010.0000000000$0.00 per ACU / month analyzed (free trial)ACU-Months

While this query is slightly more complex, what you do in the CTE is expand all the price dimensions because in some cases, there are multiple, not just one. After that, you join the data and extract the price, unit type, and description.

With these examples, you are ready to explore the pricing data available from our AWS Pricing Plugin. With simple modifications to these queries, you can get the pricing data for any service and product available from AWS.

Ready to dive deeper into your AWS pricing data? Try CloudQuery for free today and gain comprehensive insights into AWS pricing data. Contact us or join our Community to connect with other users and our engineering team, and explore the full potential of CloudQuery.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

AWS

Security

Tutorials

Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond

Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Security

Tutorials

AWS IAM Identity Center with Google Workspace as an IdP: 2026 Step-by-Step Guide

Set up AWS IAM Identity Center with Google Workspace: SAML authentication, SCIM user provisioning, and group sync with CLI or ssosync. Updated for 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Cloud Infrastructure

Security

Tutorials

Integrate AbuseIPDB Threat Intelligence with CloudQuery

Enrich your cloud asset inventory with AbuseIPDB threat intelligence to identify public cloud IPs with known abuse reports.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Cloud Infrastructure

Tutorials

How to Query ipinfo.io Data with CloudQuery

Learn how to enrich your cloud asset inventory with ipinfo.io IP geolocation and threat intelligence data using CloudQuery.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Security

Tutorials

AWS IAM Identity Center (Formerly AWS SSO): The Complete 2026 Guide

AWS IAM Identity Center replaced AWS SSO in 2022. Learn how to set it up, configure permission sets, use the AWS CLI, and audit access with CloudQuery.

Joe Karlsson

Joe Karlsson

April 6, 2026

AWS

Tutorials

AWS Pinpoint Is Being Deprecated: How to Assess Your Migration Scope

AWS Pinpoint reaches end of support October 2026. Query your Pinpoint usage across all accounts to find what needs migrating before the deadline.

Joe Karlsson

Joe Karlsson

March 24, 2026

AWS

Best Practices

Tutorials

CloudQuery Sync Performance: A Practical Troubleshooting Guide

Diagnose why CloudQuery syncs slow down after plugin upgrades, identify expensive tables, and use the CLI command that replaces the tables wildcard.

Joe Karlsson

Joe Karlsson

March 6, 2026

AWS

Security

Tutorials

Set Up AWS CLI with SSO (IAM Identity Center) — Step by Step

Configure AWS CLI v2 with IAM Identity Center in 5 minutes. Covers sso-session setup, automatic token refresh, and switching between multi-account profiles.

Yevgeny Pats

Yevgeny Pats

February 25, 2026

AWS

Cloud Infrastructure

Tutorials

AWS Lambda Python 3.9 End-of-Support: Find and Upgrade Every Affected Function

AWS Lambda Python 3.9 security patches stopped Dec 15, 2025. Find every affected function across all accounts with SQL queries and upgrade to 3.12 or 3.13.

Joe Karlsson

Joe Karlsson

February 10, 2026

Own your pipeline.
Own your data.