本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Cost Explorer 服务示例 Amazon CLI
以下代码示例向您展示了如何使用 with Cost Explorer 服务来执行操作和实现常见场景。 Amazon Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。
场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。
每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 get-cost-and-usage
。
- Amazon CLI
-
检索账户在 2017 年 9 月的 S3 使用情况
以下
get-cost-and-usage
示例检索账户在 2017 年 9 月的 S3 使用情况。aws ce get-cost-and-usage \ --time-period Start=2017-09-01,End=2017-10-01 \ --granularity MONTHLY \ --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" \ --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment \ --filter file://filters.json
filters.json
的内容:{ "Dimensions": { "Key": "SERVICE", "Values": [ "Amazon Simple Storage Service" ] } }
输出:
{ "GroupDefinitions": [ { "Type": "DIMENSION", "Key": "SERVICE" }, { "Type": "TAG", "Key": "Environment" } ], "ResultsByTime": [ { "Estimated": false, "TimePeriod": { "Start": "2017-09-01", "End": "2017-10-01" }, "Total": {}, "Groups": [ { "Keys": [ "Amazon Simple Storage Service", "Environment$" ], "Metrics": { "BlendedCost": { "Amount": "40.3527508453", "Unit": "USD" }, "UnblendedCost": { "Amount": "40.3543773134", "Unit": "USD" }, "UsageQuantity": { "Amount": "9312771.098461578", "Unit": "N/A" } } }, { "Keys": [ "Amazon Simple Storage Service", "Environment$Dev" ], "Metrics": { "BlendedCost": { "Amount": "0.2682364644", "Unit": "USD" }, "UnblendedCost": { "Amount": "0.2682364644", "Unit": "USD" }, "UsageQuantity": { "Amount": "22403.4395271182", "Unit": "N/A" } } } ] } ] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetCostAndUsage
中的。
-
以下代码示例演示如何使用 get-dimension-values
。
- Amazon CLI
-
检索维度服务的标签,值为 “Elastic”
此示例检索 2017 年 1 月 1 日至 2017 年 5 月 18 日的维度服务的标签,其值为 “Elastic”。
命令:
aws ce get-dimension-values --search-string Elastic --time-period Start=2017-01-01,End=2017-05-18 --dimension SERVICE
输出:
{ "TotalSize": 6, "DimensionValues": [ { "Attributes": {}, "Value": "Amazon ElastiCache" }, { "Attributes": {}, "Value": "EC2 - Other" }, { "Attributes": {}, "Value": "Amazon Elastic Compute Cloud - Compute" }, { "Attributes": {}, "Value": "Amazon Elastic Load Balancing" }, { "Attributes": {}, "Value": "Amazon Elastic MapReduce" }, { "Attributes": {}, "Value": "Amazon Elasticsearch Service" } ], "ReturnSize": 6 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetDimensionValues
中的。
-
以下代码示例演示如何使用 get-reservation-coverage
。
- Amazon CLI
-
检索 us-east-1 区域中 EC2 t2.nano 实例的预留覆盖范围
此示例检索 2017 年 7 月至 9 月在 us-east-1 区域的 EC2 t2.nano 实例的预留覆盖范围。
命令:
aws ce get-reservation-coverage --time-period Start=2017-07-01,End=2017-10-01 --group-by Type=Dimension,Key=REGION --filter file://filters.json
filters.json:
{ "And": [ { "Dimensions": { "Key": "INSTANCE_TYPE", "Values": [ "t2.nano" ] }, "Dimensions": { "Key": "REGION", "Values": [ "us-east-1" ] } } ] }
输出:
{ "TotalSize": 6, "DimensionValues": [ { "Attributes": {}, "Value": "Amazon ElastiCache" }, { "Attributes": {}, "Value": "EC2 - Other" }, { "Attributes": {}, "Value": "Amazon Elastic Compute Cloud - Compute" }, { "Attributes": {}, "Value": "Amazon Elastic Load Balancing" }, { "Attributes": {}, "Value": "Amazon Elastic MapReduce" }, { "Attributes": {}, "Value": "Amazon Elasticsearch Service" } ], "ReturnSize": 6 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetReservationCoverage
中的。
-
以下代码示例演示如何使用 get-reservation-purchase-recommendation
。
- Amazon CLI
-
检索期限为三年的部分预付 EC2 RI 的预留建议
以下
get-reservation-purchase-recommendation
示例根据过去 60 天的 EC2 使用情况,检索针对期限为三年的部分预付 EC2 实例的建议。aws ce get-reservation-purchase-recommendation \ --service "Amazon Redshift" \ --lookback-period-in-days SIXTY_DAYS \ --term-in-years THREE_YEARS \ --payment-option PARTIAL_UPFRONT
输出:
{ "Recommendations": [], "Metadata": { "GenerationTimestamp": "2018-08-08T15:20:57Z", "RecommendationId": "00d59dde-a1ad-473f-8ff2-iexample3330b" } }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetReservationPurchaseRecommendation
中的。
-
以下代码示例演示如何使用 get-reservation-utilization
。
- Amazon CLI
-
检索您账户的预订使用情况
以下
get-reservation-utilization
示例检索该账户在 2018-03-01 到 2018-08-01 期间所有 t2.nano 实例类型的预留实例使用率。aws ce get-reservation-utilization \ --time-period Start=2018-03-01,End=2018-08-01 \ --filter file://filters.json
filters.json
的内容:{ "Dimensions": { "Key": "INSTANCE_TYPE", "Values": [ "t2.nano" ] } }
输出:
{ "Total": { "TotalAmortizedFee": "0", "UtilizationPercentage": "0", "PurchasedHours": "0", "NetRISavings": "0", "TotalActualHours": "0", "AmortizedRecurringFee": "0", "UnusedHours": "0", "TotalPotentialRISavings": "0", "OnDemandCostOfRIHoursUsed": "0", "AmortizedUpfrontFee": "0" }, "UtilizationsByTime": [] }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetReservationUtilization
中的。
-
以下代码示例演示如何使用 get-tags
。
- Amazon CLI
-
检索成本分配标签的密钥和值
此示例检索密钥为 “项目” 且值包含 “SecretProject” 的所有成本分配标签。
命令:
aws ce get-tags --search-string secretProject --time-period Start=2017-01-01,End=2017-05-18 --tag-key Project
输出:
{ "ReturnSize": 2, "Tags": [ "secretProject1", "secretProject2" ], "TotalSize": 2 }
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考GetTags
中的。
-