Amazon Budgets 使用示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

Amazon Budgets 使用示例 Amazon CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 Amazon Budgets。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 create-budget

Amazon CLI

创建成本和使用量预算

以下create-budget命令创建成本和使用量预算。

aws budgets create-budget \ --account-id 111122223333 \ --budget file://budget.json \ --notifications-with-subscribers file://notifications-with-subscribers.json

budget.json 的内容:

{ "BudgetLimit": { "Amount": "100", "Unit": "USD" }, "BudgetName": "Example Tag Budget", "BudgetType": "COST", "CostFilters": { "TagKeyValue": [ "user:Key$value1", "user:Key$value2" ] }, "CostTypes": { "IncludeCredit": true, "IncludeDiscount": true, "IncludeOtherSubscription": true, "IncludeRecurring": true, "IncludeRefund": true, "IncludeSubscription": true, "IncludeSupport": true, "IncludeTax": true, "IncludeUpfront": true, "UseBlended": false }, "TimePeriod": { "Start": 1477958399, "End": 3706473600 }, "TimeUnit": "MONTHLY" }

notifications-with-subscribers.json 的内容:

[ { "Notification": { "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL", "Threshold": 80, "ThresholdType": "PERCENTAGE" }, "Subscribers": [ { "Address": "example@example.com", "SubscriptionType": "EMAIL" } ] } ]
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateBudget中的。

以下代码示例演示如何使用 create-notification

Amazon CLI

为指定的 “成本和使用情况” 预算创建通知

此示例为指定的 “成本和使用情况” 预算创建通知。

命令:

aws budgets create-notification --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --subscriber SubscriptionType=EMAIL,Address=example@example.com
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateNotification中的。

以下代码示例演示如何使用 create-subscriber

Amazon CLI

为与成本和使用量预算关联的通知创建订阅者

此示例为指定通知创建订阅者。

命令:

aws budgets create-subscriber --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --subscriber SubscriptionType=EMAIL,Address=example@example.com
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateSubscriber中的。

以下代码示例演示如何使用 delete-budget

Amazon CLI

删除成本和使用量预算

此示例删除了指定的成本和使用量预算。

命令:

aws budgets delete-budget --account-id 111122223333 --budget-name "Example Budget"
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteBudget中的。

以下代码示例演示如何使用 delete-notification

Amazon CLI

从预算中删除通知

此示例从指定预算中删除指定的通知。

命令:

aws budgets delete-notification --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteNotification中的。

以下代码示例演示如何使用 delete-subscriber

Amazon CLI

从通知中删除订阅者

此示例将从指定通知中删除指定的订阅者。

命令:

aws budgets delete-subscriber --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --subscriber SubscriptionType=EMAIL,Address=example@example.com
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteSubscriber中的。

以下代码示例演示如何使用 describe-budget

Amazon CLI

检索与账户关联的预算

此示例检索指定的成本和使用量预算。

命令:

aws budgets describe-budget --account-id 111122223333 --budget-name "Example Budget"

输出:

{ "Budget": { "CalculatedSpend": { "ForecastedSpend": { "Amount": "2641.54800000000022919266484677791595458984375", "Unit": "USD" }, "ActualSpend": { "Amount": "604.4560000000000172803993336856365203857421875", "Unit": "USD" } }, "BudgetType": "COST", "BudgetLimit": { "Amount": "100", "Unit": "USD" }, "BudgetName": "Example Budget", "CostTypes": { "IncludeOtherSubscription": true, "IncludeUpfront": true, "IncludeRefund": true, "UseBlended": false, "IncludeDiscount": true, "UseAmortized": false, "IncludeTax": true, "IncludeCredit": true, "IncludeSupport": true, "IncludeRecurring": true, "IncludeSubscription": true }, "TimeUnit": "MONTHLY", "TimePeriod": { "Start": 1477958399.0, "End": 3706473600.0 }, "CostFilters": { "AZ": [ "us-east-1" ] } } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeBudget中的。

以下代码示例演示如何使用 describe-budgets

Amazon CLI

检索与账户关联的预算

此示例检索账户的成本和使用量预算。

命令:

aws budgets describe-budgets --account-id 111122223333 --max-results 20

输出:

{ "Budgets": [ { "CalculatedSpend": { "ForecastedSpend": { "Amount": "2641.54800000000022919266484677791595458984375", "Unit": "USD" }, "ActualSpend": { "Amount": "604.4560000000000172803993336856365203857421875", "Unit": "USD" } }, "BudgetType": "COST", "BudgetLimit": { "Amount": "100", "Unit": "USD" }, "BudgetName": "Example Budget", "CostTypes": { "IncludeOtherSubscription": true, "IncludeUpfront": true, "IncludeRefund": true, "UseBlended": false, "IncludeDiscount": true, "UseAmortized": false, "IncludeTax": true, "IncludeCredit": true, "IncludeSupport": true, "IncludeRecurring": true, "IncludeSubscription": true }, "TimeUnit": "MONTHLY", "TimePeriod": { "Start": 1477958399.0, "End": 3706473600.0 }, "CostFilters": { "AZ": [ "us-east-1" ] } } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeBudgets中的。

以下代码示例演示如何使用 describe-notifications-for-budget

Amazon CLI

检索预算通知

此示例检索成本和使用量预算的通知。

命令:

aws budgets describe-notifications-for-budget --account-id 111122223333 --budget-name "Example Budget" --max-results 5

输出:

{ "Notifications": [ { "Threshold": 80.0, "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL" } ] }

以下代码示例演示如何使用 describe-subscribers-for-notification

Amazon CLI

检索预算通知的订阅者

此示例检索成本和使用量预算通知的订阅者。

命令:

aws budgets describe-subscribers-for-notification --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --max-results 5

输出:

{ "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "example2@example.com" }, { "SubscriptionType": "EMAIL", "Address": "example@example.com" } ] }

以下代码示例演示如何使用 update-budget

Amazon CLI

替换成本和使用情况预算的预算

此示例将成本和使用量预算替换为新预算。

命令:

aws budgets update-budget --account-id 111122223333 --new-budget file://new-budget.json

新预算.json:

{ "BudgetLimit": { "Amount": "100", "Unit": "USD" }, "BudgetName": "Example Budget", "BudgetType": "COST", "CostFilters": { "AZ" : [ "us-east-1" ] }, "CostTypes": { "IncludeCredit": false, "IncludeDiscount": true, "IncludeOtherSubscription": true, "IncludeRecurring": true, "IncludeRefund": true, "IncludeSubscription": true, "IncludeSupport": true, "IncludeTax": true, "IncludeUpfront": true, "UseBlended": false, "UseAmortized": true }, "TimePeriod": { "Start": 1477958399, "End": 3706473600 }, "TimeUnit": "MONTHLY" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateBudget中的。

以下代码示例演示如何使用 update-notification

Amazon CLI

替换成本和使用量预算的通知

此示例将成本和使用率预算的 80% 通知替换为 90% 的通知。

命令:

aws budgets update-notification --account-id 111122223333 --budget-name "Example Budget" --old-notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --new-notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=90,ThresholdType=PERCENTAGE
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateNotification中的。

以下代码示例演示如何使用 update-subscriber

Amazon CLI

根据成本和使用量预算替换订阅者

此示例取代了订阅者的 “成本和使用情况” 预算。

命令:

aws budgets update-subscriber --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE --old-subscriber SubscriptionType=EMAIL,Address=example@example.com --new-subscriber SubscriptionType=EMAIL,Address=example2@example.com
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateSubscriber中的。