

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用批量价目表 API 获取 Amazon 价目表文件
<a name="using-the-aws-price-list-bulk-api"></a>


|  | 
| --- |
| 要提供相关的反馈 Amazon 价目表，请完成这[份简短的调查](https://amazonmr.au1.qualtrics.com/jfe/form/SV_cO0deTMyKyFeezA)。您的回复将是匿名的。**注意：**本调查仅提供英文版。 | 

我们建议您在要执行以下任务时使用价目表批量处理 API：
+ 消耗大量的 Amazon Web Services 服务产品和定价信息。
+ 以高吞吐量消耗大量的 Amazon Web Services 服务产品和定价信息，例如批量处理。

此外，当价目表查询 API 无法为您的用例提供足够的吞吐量和限额时，请使用价目表批量处理 API。<a name="using-the-aws-price-list-bulk-api-fetching-price-list-files"></a>

我们建议您使用批量 Amazon 价目表 API 以编程方式查找和下载价目表文件。要获取价目表文件的 URL，请参阅以下步骤。

如果您不想使用批量 Amazon 价目表 API，可以手动下载价目表文件。有关更多信息，请参阅 [手动获取价目表文件](using-the-aws-price-list-bulk-api-fetching-price-list-files-manually.md)。

### 第 1 步：查找可用 Amazon Web Services 服务
<a name="price-bulk-api-step-1-find-available-services"></a>

使用 `DescribeServices` API 操作查找价目表批量处理 API 支持的所有可用 Amazon Web Services 服务 。此 API 操作返回服务列表中的 `ServiceCode` 值。您稍后使用此值来查找相关的价目表文件。

**Example 示例：查找可用服务**  
以下命令说明如何查找可用的 Amazon Web Services 服务。  

```
aws pricing describe-services --region cn-northwest-1
```
 Amazon Web Services 区域 是价目表批量 API 的 API 端点。端点与产品或服务属性无关。  
**响应**  

```
{
    "FormatVersion": "aws_v1", 
    "NextToken": "abcdefg123", 
    "Services": [ 
        {
            "AttributeNames": [ 
                "volumeType", 
                "maxIopsvolume", 
                "instanceCapacity10xlarge", 
                "locationType", 
                "operation" 
            ], 
            "ServiceCode": "AmazonEC2" 
        },
        {
            "AttributeNames": [ 
                "productFamily", 
                "volumeType", 
                "engineCode", 
                "memory" 
            ], 
            "ServiceCode": "AmazonRDS" 
        },
        {...} 
    ] 
}
```

*有关此 API 操作的更多信息，请参阅《API 参考》 Amazon SDKs中的 “[https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_DescribeServices.html](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_DescribeServices.html)Amazon 账单与成本管理 和[特定语言](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_DescribeServices.html#API_pricing_DescribeServices_SeeAlso)”*

**注意**  
虽然 Savings Plans 目前不返回 `DescribeServices` `serviceCodes` API，但您需要满足以下条件`serviceCodes`才能在后续的 API 调用中使用储蓄计划：  


| ServiceCode | SavingsPlanCode | 
| --- | --- | 
| ComputeSavingsPlans | AWSComputeSavingsPlan | 
| MachineLearningSavingsPlans | AWSMachineLearningSavingsPlans | 
| DatabaseSavingsPlans | AWSDatabaseSavingsPlans | 
使用`ListPriceLists`和 `GetPriceListFileUrl` API 操作时使用这些`ServiceCode`值。`SavingsPlanCode`仅当您手动下载价目表文件而不是使用时，才需要 APIs。

### 步骤 2：查找可用价目表文件 Amazon Web Services 服务
<a name="price-list-bulk-api-step-2-find-available-price-list-files"></a>

使用 `ListPriceLists` API 操作获取您有权查看的价目表参考清单。要筛选结果，您可以指定 `ServiceCode`、`CurrencyCode`、和 `EffectiveDate` 参数。

 Amazon Web Services 区域 是价目表批量 API 的 API 端点。端点与产品或服务属性无关。

#### 查找价目表文件的示例
<a name="price-list-bulk-api-examples-find-price-list-files"></a>

**Example 示例：查找所有人的价目表文件 Amazon Web Services 区域**  
如果您未指定 `--region-code` 参数，则 API 操作会返回所有可用 Amazon Web Services 区域的价目表文件参考。  

```
aws pricing list-price-lists --service-code AmazonRDS --currency-code USD --effective-date "2023-04-03 00:00"
```
**响应**  

```
{
   "NextToken": "abcd1234",
   "PriceLists": [ 
      { 
         "CurrencyCode": "USD",
         "FileFormats": [ "json", "csv" ],
         "PriceListArn": "arn:cn:pricing:::price-list/cn/AmazonRDS/USD/20230328234721/cn-northwest-1",
         "RegionCode": "cn-northwest-1"
      },
      { 
         "CurrencyCode": "USD",
         "FileFormats": [ "json", "csv" ],
         "PriceListArn": "arn:cn:pricing:::price-list/cn/AmazonRDS/USD/20230328234721/cn-northwest-1",
         "RegionCode": "cn-northwest-1"
      },
      ...
   ]
}
```

**Example 示例：查找特定区域的价目表文件**  
如果您指定 `RegionCode` 参数，API 操作将返回该区域特定的价目表文件参考。要查找历史价目表文件，请使用 `EffectiveDate` 参数。例如，您可以指定过去的日期来查找特定的价目表文件。  
然后，您可以从响应中将 `PriceListArn` 值与 [https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetPriceListFileUrl.html](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetPriceListFileUrl.html) API 操作配合使用，以获取您的首选价目表文件。  

```
aws pricing list-price-lists --service-code AmazonRDS --currency-code USD --region-code cn-northwest-1 --effective-date "2023-04-03 00:00"
```
**响应**  

```
{
   "PriceLists": [ 
      { 
         "CurrencyCode": "USD",
         "FileFormats": [ "json", "csv" ],
         "PriceListArn": "arn:cn:pricing:::price-list/cn/AmazonRDS/USD/20230328234721/cn-northwest-1",
         "RegionCode": "cn-northwest-1"
      }
   ]
}
```

*有关此 API 操作的更多信息，请参阅《API 参考》 Amazon SDKs中的 “[https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_ListPriceLists.html](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_ListPriceLists.html)Amazon 账单与成本管理 和[特定语言](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_ListPriceLists.html#API_pricing_ListPriceLists_SeeAlso)”。*

### 步骤 3：获取特定的价目表文件
<a name="price-list-bulk-api-step-3-getting-specific-price-list"></a>

使用 `GetPriceListFileUrl` API 操作获取价目表文件的 URL。此 URL 基于您在[第 1 步](#price-bulk-api-step-1-find-available-services)和[第 2 步](#price-list-bulk-api-step-2-find-available-price-list-files)中从 `ListPriceLists` 响应中检索到的 `PriceListArn` 和 `FileFormats` 值。

**Example 示例：获取特定的价目表文件**  
以下命令获取 Amazon RDS 特定价目表文件的 URL。  

```
aws pricing get-price-list-file-url --price-list-arn arn:cn:pricing:::price-list/cn/AmazonRDS/USD/20230328234721/cn-northwest-1 --file-format json --region cn-northwest-1
```
**响应**  

```
{
    "Url": "https://pricing.cn-northwest-1.amazonaws.com/offers/v1.0/aws/AmazonRDS/20230328234721/cn-northwest-1/index.json"
}
```
从响应中，您可以使用 URL 下载价目表文件。

有关此 API 操作的更多信息，请参阅以下主题：
+  [https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetPriceListFileUrl.html](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetPriceListFileUrl.html)*并在 [API 参考 Amazon SDKs中针对特定语言](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetPriceListFileUrl.html#API_pricing_GetPriceListFileUrl_SeeAlso)Amazon 账单与成本管理 *
+ [读取价目表文件](bulk-api-reading-price-list-files.md)