You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Cost Explorer boto3方法可用的AWS服务变量名称?

Got it, I totally feel your pain with those inconsistent service names in Cost Explorer—trying to guess them by trial and error is such a time sink. The good news is there's an official way to get the exact, up-to-date list of valid SERVICE dimension names instead of relying on scattered docs or guesswork.

How to Get Exact Service Names for Cost Explorer's SERVICE Dimension

First, let's clear up the confusion: the service names required by Cost Explorer's API are normalized service names that don't always match common shorthand or console display names. Instead of guessing, you can pull the full, valid list directly via the AWS API or console.

1. Use the Cost Explorer API to Fetch Valid Service Names

The most reliable way is to call the get_dimension_values method with the SERVICE dimension. This returns all service names that have cost data associated with your account (or all available AWS services, depending on your setup).

Here's a Python/boto3 snippet to do this:

import boto3

def get_all_valid_service_names():
    ce = boto3.client('ce')
    response = ce.get_dimension_values(
        TimePeriod={
            'Start': '2024-01-01',  # Use a range that covers your actual usage
            'End': '2024-01-31'
        },
        Dimension='SERVICE',
        Context='COST_AND_USAGE'
    )
    # Extract and return the clean list of service names
    return [item['Value'] for item in response['DimensionValues']]

# Run to get your valid service names
for name in get_all_valid_service_names():
    print(name)

This will output every service name you can safely use in your get_cost_and_usage call.

2. Check the AWS Console (GUI Approach)

If you prefer clicking around instead of writing code:

  • Open the Cost Explorer console
  • Create a new cost report (or edit an existing one)
  • Under Group by, select Service
  • The dropdown will show all valid service names tied to your account's usage. You can copy these directly into your code.

Fixing Your Specific Service Issues

For the two services that weren't working for you:

  • Amazon CodeBuild: If your account has active CodeBuild usage, the API/console will confirm Amazon CodeBuild is valid. If you're getting no data, double-check your time period to ensure there's cost activity in that range.
  • AWS CodePipeline: The correct normalized name is almost certainly AWS CodePipeline (not AWS Code Pipeline - Service). The API snippet above will verify this for your account.

Why the Names Seem Inconsistent

AWS uses these normalized names to align with their internal service categorization—some use the full "Amazon" prefix, others use "AWS", and some have suffixes like "- Compute" (like EC2) because it falls under a broader compute category. The API/console methods are the only guaranteed way to get names that work every time.

内容的提问来源于stack exchange,提问作者nephele

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 14:37:44