

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

# 使用 Amazon 价目表查询 API 查找服务和产品
<a name="using-price-list-query-api"></a>


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

我们建议您在以下情况下使用价目表查询 API：
+ 查找有关某个产品的定价信息。
+ 搜索与您的筛选条件相匹配的产品和价格。
+ 在开发资源有限的应用程序（例如前端环境）时，快速查找所需的产品和价格。

要查找 Amazon Web Services 服务他们的产品以及产品属性和价格，请参阅以下步骤。

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

找到服务后，即可使用 `DescribeServices` API 操作获取其属性。如果您知道服务代码，也可以使用 Amazon 价目表查询 API 来获取服务的属性。然后，您可以使用服务属性根据属性值查找符合您要求的产品。

### 示例：查找服务
<a name="examples-cli-price-list-query-api"></a>

以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何查找服务。

**Example 示例：查找所有服务**  

```
aws pricing describe-services --region cn-northwest-1
```
**响应**  

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

**Example 示例：查找 Amazon Elastic Compute Cloud（Amazon EC2）的服务元数据**  
以下命令显示了如何查找 Amazon EC2 的服务元数据。  

```
aws pricing describe-services --region cn-northwest-1 --service-code AmazonEC2
```
**响应**  

```
{
    "FormatVersion": "aws_v1", 
    "NextToken": "abcdefg123", 
    "Services": [ 
        {
            "AttributeNames": [ 
                "productFamily", 
                "volumeType", 
                "engineCode", 
                "memory" 
            ], 
            "ServiceCode": "AmazonEC2" 
        }
    ] 
}
```

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

有关更多信息，请参阅《Amazon 账单与成本管理 API Reference》**中的 [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)。

## 步骤 2：查找属性的可用值
<a name="price-list-query-api-find-attributes"></a>

在[步骤 1](#price-list-query-api-find-services) 中，您检索了 Amazon Web Services 服务的属性列表。在此步骤中，您将使用这些属性来搜索产品。在步骤 3 中，您需要这些属性的可用值。

要查询属性的值，请使用 `GetAttributeValues` API 操作。如需调用 API，请指定 `AttributeName` 和 `ServiceCode` 参数。

### 示例：获取属性值
<a name="examples-to-find-attributes"></a>

以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何获取的属性值 Amazon Web Services 服务。

**Example 示例：查询 Amazon Relational Database Service（Amazon RDS）的属性值**  

```
aws pricing get-attribute-values --service-code AmazonRDS --attribute-name operation --region cn-northwest-1
```
**响应**  

```
{
    "AttributeValues": [
        {
            "Value": "CreateDBInstance:0002"
        },
        {
            "Value": "CreateDBInstance:0003"
        },
        {
            "Value": "CreateDBInstance:0004"
        },
        {
            "Value": "CreateDBInstance:0005"
        }
    ],
    "NextToken": "abcdefg123"
}
```

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

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

## 步骤 3：根据属性查找产品
<a name="using-the-aws-price-list-query-api-finding-products-from-attributes"></a>

在此步骤中，您将使用[步骤 1](#price-list-query-api-find-services) 和[步骤 2](#price-list-query-api-find-attributes) 中的信息来查找产品及其期限。要获取产品相关信息，请使用 `GetProducts` API 操作。您可以指定筛选条件列表来返回您想要的产品。

**注意**  
价目表查询 API 仅支持 `"AND"` 匹配。对您的命令的响应仅包含与所有指定筛选条件匹配的产品。

### 示例：根据属性查找商品
<a name="example-cli-filters-for-finding-products-from-attributes"></a>

以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何使用属性查找产品。

**Example 示例：查找具有指定筛选条件的产品**  
以下命令显示了如何为 Amazon Relational Database Service（Amazon RDS）指定筛选条件。  

```
aws pricing get-products --service-code AmazonRDS --region cn-northwest-1 --filters Type=TERM_MATCH,Field=operation,Value="CreateDBInstance:0002"
```
**响应**  

```
{
    "FormatVersion": "aws_v1",
    "PriceList": ["{
        \"product\":{
            \"productFamily\":\"Database Instance\",
            \"attributes\":{
                \"engineCode\":\"2\",
                \"enhancedNetworkingSupported\":\"Yes\",
                \"memory\":\"64 GiB\",
                \"dedicatedEbsThroughput\":\"2000 Mbps\",
                \"vcpu\":\"16\",
                \"locationType\":\"AWS Region\",
                \"storage\":\"EBS Only\",
                \"instanceFamily\":\"General purpose\",
                \"regionCode\":\"cn-northwest-1\",
                \"operation\":\"CreateDBInstance:0002\",
                ...
            },
            \"sku\":\"22ANV4NNQP3UUCWY\"},
            \"serviceCode\":\"AmazonRDS\",
            \"terms\":{...}"
    ],
    "NextToken": "abcd1234"
}
```

**Example 示例：使用 `filters.json` 文件指定筛选条件**  
以下命令显示如何指定包含所有筛选条件的 JSON 文件。  

```
aws pricing get-products --service-code AmazonRDS --region cn-northwest-1 --filters file://filters.json
```
例如，`filters.json` 文件可能包含以下筛选条件。  

```
[
  {
    "Type": "TERM_MATCH",
    "Field": "operation",
    "Value": "CreateDBInstance:0002"
  }
]
```
以下示例说明如何指定多个筛选条件。  

```
[
  {
    "Type": "TERM_MATCH",
    "Field": "AttributeName1",
    "Value": "AttributeValue1"
  },
  {
    "Type": "TERM_MATCH",
    "Field": "AttributeName2",
    "Value": "AttributeValue2"
  },
  ...
]
```
**响应**  

```
{
    "FormatVersion": "aws_v1",
    "PriceList": ["{
        \"product\":{
            \"productFamily\":\"Database Instance\",
            \"attributes\":{
                \"engineCode\":\"2\",
                \"enhancedNetworkingSupported\":\"Yes\",
                \"memory\":\"64 GiB\",
                \"dedicatedEbsThroughput\":\"2000 Mbps\",
                \"vcpu\":\"16\",
                \"locationType\":\"AWS Region\",
                \"storage\":\"EBS Only\",
                \"instanceFamily\":\"General purpose\",
                \"regionCode\":\"cn-northwest-1\",
                \"operation\":\"CreateDBInstance:0002\",
                ...
            },
            \"sku\":\"22ANV4NNQP3UUCWY\"},
            \"serviceCode\":\"AmazonRDS\",
            \"terms\":{...}"
    ],
    "NextToken": "abcd1234"
}
```

有关更多信息，请参阅以下主题：
+ [https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetProducts.html](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetProducts.html)*并在 [API 参考 Amazon SDKs中针对特定语言](https://docs.amazonaws.cn/aws-cost-management/latest/APIReference/API_pricing_GetProducts.html#API_pricing_GetProducts_SeeAlso)Amazon 账单与成本管理 *
+ [读取服务价目表文件](reading-service-price-list-files.md)
+ [在服务价目表文件中查找价格](finding-prices-in-service-price-list-files.md)