本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Amazon 价目表查询 API 查找服务和产品
要提供相关的反馈 Amazon 价目表,请完成这份简短的调查 |
我们建议您在以下情况下使用价目表查询 API:
-
查找有关某个产品的定价信息。
-
搜索与您的筛选条件相匹配的产品和价格。
-
在开发资源有限的应用程序(例如前端环境)时,快速查找所需的产品和价格。
要查找 Amazon Web Services他们的产品以及产品属性和价格,请参阅以下步骤。
找到服务后,即可使用 DescribeServices
API 操作获取其属性。如果您知道服务代码,也可以使用 Amazon 价目表查询 API 来获取服务的属性。然后,您可以使用服务属性根据属性值查找符合您要求的产品。
示例:查找服务
以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何查找服务。
例 示例:查找所有服务
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" }, {...} ] }
例 示例:查找 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 Billing and Cost Management API 参考》中的 DescribeServices。
在步骤 1 中,您检索了 Amazon Web Service的属性列表。在此步骤中,您将使用这些属性来搜索产品。在步骤 3 中,您需要这些属性的可用值。
要查询属性的值,请使用 GetAttributeValues
API 操作。如需调用 API,请指定 AttributeName
和 ServiceCode
参数。
示例:获取属性值
以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何获取的属性值 Amazon Web Service。
例 示例:查询 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 端点。端点与产品或服务属性无关。
有关更多信息,请参阅《API 参考》中的GetAttributeValues和特定语言的 Amazon SDK。Amazon Billing and Cost Management
在此步骤中,您将使用步骤 1 和步骤 2 中的信息来查找产品及其期限。要获取产品相关信息,请使用 GetProducts
API 操作。您可以指定筛选条件列表来返回您想要的产品。
注意
价目表查询 API 仅支持 "AND"
匹配。对您的命令的响应仅包含与所有指定筛选条件匹配的产品。
示例:根据属性查找商品
以下 Amazon Command Line Interface (Amazon CLI) 命令显示如何使用属性查找产品。
例 示例:查找具有指定筛选条件的产品
以下命令显示了如何为 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" }
例 示例:使用 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" }
有关更多信息,请参阅以下主题:
-
GetProducts以及 AP I 参考中包含特定语言的 Amazon SDKAmazon Billing and Cost Management