aws-cost-explorer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AWS Cost Explorer

AWS Cost Explorer

Query AWS costs and usage details with flexible granularity - from service-level overview to detailed usage type breakdown.
查询AWS成本和使用详情,支持灵活的粒度——从服务级概览到详细的使用类型细分。

Capabilities

功能

  • Query daily AWS costs by service (e.g., EC2, S3, OpenSearch, DocumentDB)
  • Drill down to usage type details for specific services (e.g., instance types, storage, data transfer)
  • Filter results by minimum cost threshold
  • Support both relative dates (days ago) and absolute dates (YYYY-MM-DD)
  • Output in human-readable table or JSON format
  • 按服务查询每日AWS成本(如EC2、S3、OpenSearch、DocumentDB)
  • 深入查看特定服务的使用类型详情(如实例类型、存储、数据传输)
  • 按最低成本阈值过滤结果
  • 支持相对日期(几天前)和绝对日期(YYYY-MM-DD)
  • 输出人类可读的表格或JSON格式

Usage

使用方法

Quick Commands

快速命令

To query costs, use the bundled script at
scripts/cost_query.py
:
bash
undefined
要查询成本,使用
scripts/cost_query.py
中的捆绑脚本:
bash
undefined

Query costs from 2 days ago (default) by service

查询2天前(默认)的按服务划分的成本

python3 <skill-path>/scripts/cost_query.py
python3 <skill-path>/scripts/cost_query.py

Query yesterday's costs, show items > $5

查询昨天的成本,显示金额超过5美元的项目

python3 <skill-path>/scripts/cost_query.py --days-ago 1 --min-cost 5
python3 <skill-path>/scripts/cost_query.py --days-ago 1 --min-cost 5

Query specific date

查询特定日期的成本

python3 <skill-path>/scripts/cost_query.py --date 2026-01-15
python3 <skill-path>/scripts/cost_query.py --date 2026-01-15

Query specific service's usage breakdown

查询特定服务的使用细分

python3 <skill-path>/scripts/cost_query.py --service "Amazon OpenSearch Service" --min-cost 1
python3 <skill-path>/scripts/cost_query.py --service "Amazon OpenSearch Service" --min-cost 1

Query all services with usage type details

查询所有服务的使用类型详情

python3 <skill-path>/scripts/cost_query.py --detailed --min-cost 5
python3 <skill-path>/scripts/cost_query.py --detailed --min-cost 5

Output as JSON

以JSON格式输出

python3 <skill-path>/scripts/cost_query.py --json --min-cost 5
undefined
python3 <skill-path>/scripts/cost_query.py --json --min-cost 5
undefined

Script Options

脚本选项

OptionShortDescription
--days-ago
-d
Query N days ago (default: 2, i.e., day before yesterday)
--date
Query specific date (YYYY-MM-DD format)
--min-cost
-m
Minimum cost threshold to display (default: 0)
--service
-s
Query usage type breakdown for a specific service
--detailed
Show all services with usage type breakdown
--json
-j
Output in JSON format
选项简写描述
--days-ago
-d
查询N天前的成本(默认:2,即前天)
--date
查询特定日期的成本(格式为YYYY-MM-DD)
--min-cost
-m
显示结果的最低成本阈值(默认:0)
--service
-s
查询特定服务的使用类型细分
--detailed
显示所有服务的使用类型详情
--json
-j
以JSON格式输出

Common Service Names

常用服务名称

When using
--service
, use the exact AWS service names:
Common NameAWS Service Name
OpenSearch
Amazon OpenSearch Service
DocumentDB/MongoDB
Amazon DocumentDB (with MongoDB compatibility)
EC2 Compute
Amazon Elastic Compute Cloud - Compute
EC2 Other (EBS, NAT)
EC2 - Other
EFS
Amazon Elastic File System
S3
Amazon Simple Storage Service
RDS
Amazon Relational Database Service
EKS
Amazon Elastic Container Service for Kubernetes
VPC
Amazon Virtual Private Cloud
Bedrock
Amazon Bedrock
Lambda
AWS Lambda
CloudWatch
AmazonCloudWatch
使用
--service
选项时,请使用准确的AWS服务名称:
常用名称AWS服务名称
OpenSearch
Amazon OpenSearch Service
DocumentDB/MongoDB
Amazon DocumentDB (with MongoDB compatibility)
EC2计算
Amazon Elastic Compute Cloud - Compute
EC2其他(EBS、NAT)
EC2 - Other
EFS
Amazon Elastic File System
S3
Amazon Simple Storage Service
RDS
Amazon Relational Database Service
EKS
Amazon Elastic Container Service for Kubernetes
VPC
Amazon Virtual Private Cloud
Bedrock
Amazon Bedrock
Lambda
AWS Lambda
CloudWatch
AmazonCloudWatch

Understanding Usage Types

理解使用类型

Common usage type patterns:
PatternMeaning
BoxUsage:*
EC2 instance hours (e.g.,
BoxUsage:m7i.large
)
ESInstance:*
OpenSearch instance hours
EBS:VolumeUsage.*
EBS storage (e.g.,
EBS:VolumeUsage.gp3
)
TimedStorage-ByteHrs
S3/EFS storage capacity
DataTransfer-*
Data transfer costs
NatGateway-*
NAT Gateway costs
VpcEndpoint-*
VPC Endpoint costs
*-input-tokens
/
*-output-tokens
Bedrock token usage
Elastic*Usage
DocumentDB Elastic costs
常见的使用类型模式:
模式含义
BoxUsage:*
EC2实例时长(如
BoxUsage:m7i.large
ESInstance:*
OpenSearch实例时长
EBS:VolumeUsage.*
EBS存储(如
EBS:VolumeUsage.gp3
TimedStorage-ByteHrs
S3/EFS存储容量
DataTransfer-*
数据传输成本
NatGateway-*
NAT网关成本
VpcEndpoint-*
VPC终端节点成本
*-input-tokens
/
*-output-tokens
Bedrock令牌使用量
Elastic*Usage
DocumentDB Elastic成本

Prerequisites

前提条件

  • AWS CLI configured with appropriate credentials
  • IAM permissions for
    ce:GetCostAndUsage
  • 已配置具有适当凭证的AWS CLI
  • 拥有
    ce:GetCostAndUsage
    的IAM权限

Example Workflow

示例工作流

  1. First, get service-level overview:
    bash
    python3 <skill-path>/scripts/cost_query.py --min-cost 5
  2. Identify high-cost services, then drill down:
    bash
    python3 <skill-path>/scripts/cost_query.py --service "Amazon OpenSearch Service" --min-cost 1
  3. For comprehensive analysis, use detailed mode:
    bash
    python3 <skill-path>/scripts/cost_query.py --detailed --min-cost 5
  1. 首先,获取服务级概览:
    bash
    python3 <skill-path>/scripts/cost_query.py --min-cost 5
  2. 识别高成本服务,然后深入查看:
    bash
    python3 <skill-path>/scripts/cost_query.py --service "Amazon OpenSearch Service" --min-cost 1
  3. 如需全面分析,使用详细模式:
    bash
    python3 <skill-path>/scripts/cost_query.py --detailed --min-cost 5