Skip to content

Query ElastiCache Redis and Valkey Clusters in AWS Cost and Usage Report (CUR) with Athena

2 minute read
Content level: Expert
0

This article provides ready-to-use Amazon Athena SQL queries to identify and analyze Amazon ElastiCache clusters running Redis or Valkey engines across AWS accounts using Cost and Usage Report (CUR) data. Useful for cost optimization, multi-account inventory, and tracking Redis to Valkey migrations.

Overview

This guide shows you how to identify all Amazon ElastiCache clusters running Redis or Valkey engines across your AWS accounts using AWS Cost and Usage Report (CUR) data queried through Amazon Athena.

Prerequisites

  • AWS Cost and Usage Report enabled and configured
  • CUR data integrated with Amazon Athena
  • Appropriate IAM permissions for Athena queries

The Athena Query

Query to list all ElastiCache Redis and Valkey clusters from CUR

SELECT DISTINCT
  line_item_usage_account_id as account_id,
  SPLIT_PART(line_item_resource_id, ':', 7) as cluster_id,
  product_cache_engine as cache_engine,
  SPLIT_PART(line_item_usage_type, ':', 2) as instance_type,
  product_location as region
FROM "your_cur_table_name"  -- Replace with your actual CUR table name
WHERE line_item_product_code = 'AmazonElastiCache'
  AND product_cache_engine IN ('Redis', 'Valkey')
  AND line_item_line_item_type IN ('DiscountedUsage', 'Usage')
ORDER BY cache_engine, account_id, cluster_id;

Query Explanation

  • line_item_usage_account_id: Identifies the AWS account running the cluster
  • SPLIT_PART(line_item_resource_id, ':', 7): Extracts cluster ID from the resource ARN
  • product_cache_engine IN ('Redis', 'Valkey'): Filters for specific cache engines

What the Results Include Account ID, Cluster ID, Cache engine (Redis or Valkey), Instance type/size, AWS Region