AWS Price CSV Skill
Overview
Transforms a user-provided AWS service list (instances, volumes, S3 buckets, etc.) into a pricing CSV. The script can query the AWS Price List API (via
aws-cli) or reuse cached bulk JSON files. It supports On-Demand and Reserved terms and automatically adds up per-item and total costs.
Quick Start
- 1. Prepare a YAML/JSON file with
name, service_code, filters, term, and usage fields (see sample in references/api_reference.md). - Pick the data source:
-
API mode – requires
aws pricing get-products permission and an internet connection.
-
Bulk mode – no IAM access required; the script downloads/caches public bulk JSON files.
- 3. Run the script with the region and desired options:
python3 scripts/generate_pricing_csv.py \
--input inputs/sample.yml \
--region ap-northeast-1 \
--source bulk \
--cache-dir ~/.cache/aws-price-csv \
--output quotes/apac_quote.csv
- 4. Inspect the CSV (each line item + TOTAL) and deliver alongside the original request if needed.
Workflow
1. Prepare the input list
- - Use the YAML/JSON templates in
references/api_reference.md. - INLINECODE9 must map to AWS pricing attributes (
instanceType, regionCode, volumeApiName, usagetype, termType, etc.). - INLINECODE15 :
OnDemand or Reserved (RI). - INLINECODE19 (optional) filter Reserved prices (
LeaseContractLength, PurchaseOption, OfferingClass, ...). - INLINECODE23 represents the amount to multiply (hours, GB-Mo, requests, ...).
2. Choose the data source
| Mode | When to use | Notes |
|---|
API (--source api) | You already have IAM creds and want real-time data | Uses aws pricing get-products in INLINECODE26 |
Bulk (--source bulk) |
Offline, no IAM, or you want caching | The script checks
--cache-dir (default
~/.cache/aws-price-csv); cached files newer than 30 days are reused, otherwise they are re-downloaded |
You can still override with --bulk-files ServiceCode=/path/to/file.json; those files win over the cache.
3. Generate the CSV
- - Script path: INLINECODE31
- Key arguments:
-
--input: YAML/JSON list
-
--region: AWS region code (location name is auto-added to filters)
-
--output: CSV path (default
aws_pricing.csv)
-
--source:
api (default) or
bulk
-
--cache-dir: bulk cache directory (default
~/.cache/aws-price-csv)
-
--force-refresh: ignore cached bulk files and re-download
-
--bulk-files:
ServiceCode=/path/to/file.json overrides the cache
- - Output columns:
item_name, service_code, term_type, region, location, quantity, usage_unit, price_unit, price_per_unit_usd, cost_usd, description, plus a TOTAL row.
4. Validate & deliver
- - Review the CSV to ensure every line item has pricing and a description.
- Confirm the
TOTAL matches expectations. - Include the source list or any supporting docs if required.
Troubleshooting
| Issue | Fix |
|---|
| INLINECODE47 returns empty results | Double-check filters (location, regionCode, termType, etc.) or fall back to bulk mode |
| INLINECODE48 CLI missing |
Install aws-cli v2, configure credentials, or rely on bulk mode |
| Need to refresh cached data | Use
--force-refresh or delete the cached JSON so it gets re-downloaded |
| PyYAML missing |
pip install pyyaml or convert input to JSON |
| Reserved price not found | Add
LeaseContractLength,
PurchaseOption,
OfferingClass inside
term.attributes |
Resources
- -
scripts/generate_pricing_csv.py – main script with API/bulk support, caching logic, and On-Demand/Reserved handling. - INLINECODE56 – Price List API examples, bulk download pointers, region/location table, and sample input templates (including gp3 and RI cases).
AWS 价格 CSV 技能
概述
将用户提供的 AWS 服务列表(实例、卷、S3 存储桶等)转换为定价 CSV。该脚本可以查询 AWS 价格列表 API(通过 aws-cli)或重用缓存的批量 JSON 文件。它支持按需和预留实例条款,并自动计算每个项目及总成本。
快速开始
- 1. 准备一个包含 name、servicecode、filters、term 和 usage 字段的 YAML/JSON 文件(参见 references/apireference.md 中的示例)。
- 选择数据源:
-
API 模式 – 需要 aws pricing get-products 权限和互联网连接。
-
批量模式 – 无需 IAM 访问权限;脚本会下载/缓存公共批量 JSON 文件。
- 3. 使用区域和所需选项运行脚本:
bash
python3 scripts/generate
pricingcsv.py \
--input inputs/sample.yml \
--region ap-northeast-1 \
--source bulk \
--cache-dir ~/.cache/aws-price-csv \
--output quotes/apac_quote.csv
- 4. 检查 CSV(每个行项目 + 总计),如有需要可与原始请求一起交付。
工作流程
1. 准备输入列表
- - 使用 references/api_reference.md 中的 YAML/JSON 模板。
- filters 必须映射到 AWS 定价属性(instanceType、regionCode、volumeApiName、usagetype、termType 等)。
- term.type:OnDemand 或 Reserved(RI)。
- term.attributes(可选)过滤预留价格(LeaseContractLength、PurchaseOption、OfferingClass 等)。
- usage.quantity 表示要乘的数值(小时、GB-月、请求数等)。
2. 选择数据源
| 模式 | 使用场景 | 说明 |
|---|
| API(--source api) | 已有 IAM 凭证且需要实时数据 | 在 us-east-1 区域使用 aws pricing get-products |
| 批量(--source bulk) |
离线、无 IAM 或需要缓存 | 脚本检查 --cache-dir(默认 ~/.cache/aws-price-csv);30 天内的缓存文件会被重用,否则重新下载 |
仍可通过 --bulk-files ServiceCode=/path/to/file.json 覆盖;这些文件优先级高于缓存。
3. 生成 CSV
- - 脚本路径:scripts/generatepricingcsv.py
- 关键参数:
- --input:YAML/JSON 列表
- --region:AWS 区域代码(位置名称会自动添加到过滤条件中)
- --output:CSV 路径(默认 aws_pricing.csv)
- --source:api(默认)或 bulk
- --cache-dir:批量缓存目录(默认 ~/.cache/aws-price-csv)
- --force-refresh:忽略缓存的批量文件并重新下载
- --bulk-files:ServiceCode=/path/to/file.json 覆盖缓存
- - 输出列:itemname, servicecode, termtype, region, location, quantity, usageunit, priceunit, priceperunitusd, cost_usd, description,外加一个 TOTAL 行。
4. 验证并交付
- - 检查 CSV 确保每个行项目都有定价和描述。
- 确认 TOTAL 符合预期。
- 如有需要,附上源列表或任何支持文档。
故障排除
| 问题 | 解决方法 |
|---|
| aws pricing 返回空结果 | 仔细检查过滤条件(location、regionCode、termType 等),或回退到批量模式 |
| 缺少 aws CLI |
安装 aws-cli v2,配置凭证,或依赖批量模式 |
| 需要刷新缓存数据 | 使用 --force-refresh 或删除缓存的 JSON 文件以重新下载 |
| 缺少 PyYAML | pip install pyyaml 或将输入转换为 JSON |
| 未找到预留价格 | 在 term.attributes 中添加 LeaseContractLength、PurchaseOption、OfferingClass |
资源
- - scripts/generatepricingcsv.py – 主脚本,支持 API/批量模式、缓存逻辑以及按需/预留实例处理。
- references/api_reference.md – 价格列表 API 示例、批量下载指南、区域/位置表以及示例输入模板(包括 gp3 和 RI 案例)。