This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
Amazon Budgets examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon Budgets.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-budget
.
- Amazon CLI
-
To create a Cost and Usage budget
The following
create-budget
command creates a Cost and Usage budget.aws budgets create-budget \ --account-id
111122223333
\ --budgetfile://budget.json
\ --notifications-with-subscribersfile://notifications-with-subscribers.json
Contents of
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" }
Contents of
notifications-with-subscribers.json
:[ { "Notification": { "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL", "Threshold": 80, "ThresholdType": "PERCENTAGE" }, "Subscribers": [ { "Address": "example@example.com", "SubscriptionType": "EMAIL" } ] } ]
-
For API details, see CreateBudget
in Amazon CLI Command Reference.
-
The following code example shows how to use create-notification
.
- Amazon CLI
-
To create a notification for the specified Cost and Usage budget
This example creates a notification for the specified Cost and Usage budget.
Command:
aws budgets create-notification --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--subscriberSubscriptionType=EMAIL,Address=example@example.com
-
For API details, see CreateNotification
in Amazon CLI Command Reference.
-
The following code example shows how to use create-subscriber
.
- Amazon CLI
-
To create a subscriber for a notification associated with a Cost and Usage budget
This example creates a subscriber for the specified notification.
Command:
aws budgets create-subscriber --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--subscriberSubscriptionType=EMAIL,Address=example@example.com
-
For API details, see CreateSubscriber
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-budget
.
- Amazon CLI
-
To delete a Cost and Usage budget
This example deletes the specified Cost and Usage budget.
Command:
aws budgets delete-budget --account-id
111122223333
--budget-name"Example Budget"
-
For API details, see DeleteBudget
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-notification
.
- Amazon CLI
-
To delete a notification from a budget
This example deletes the specified notification from the specified budget.
Command:
aws budgets delete-notification --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
-
For API details, see DeleteNotification
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-subscriber
.
- Amazon CLI
-
To delete a subscriber from a notification
This example deletes the specified subscriber from the specified notification.
Command:
aws budgets delete-subscriber --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--subscriberSubscriptionType=EMAIL,Address=example@example.com
-
For API details, see DeleteSubscriber
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-budget
.
- Amazon CLI
-
To retrieve a budget associated with an account
This example retrieves the specified Cost and Usage budget.
Command:
aws budgets describe-budget --account-id
111122223333
--budget-name"Example Budget"
Output:
{ "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" ] } } }
-
For API details, see DescribeBudget
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-budgets
.
- Amazon CLI
-
To retrieve the budgets associated with an account
This example retrieves the Cost and Usage budgets for an account.
Command:
aws budgets describe-budgets --account-id
111122223333
--max-results20
Output:
{ "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" ] } } ] }
-
For API details, see DescribeBudgets
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-notifications-for-budget
.
- Amazon CLI
-
To retrieve the notifications for a budget
This example retrieves the notifications for a Cost and Usage budget.
Command:
aws budgets describe-notifications-for-budget --account-id
111122223333
--budget-name"Example Budget"
--max-results5
Output:
{ "Notifications": [ { "Threshold": 80.0, "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL" } ] }
-
For API details, see DescribeNotificationsForBudget
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-subscribers-for-notification
.
- Amazon CLI
-
To retrieve the subscribers for a budget notification
This example retrieves the subscribers for a Cost and Usage budget notification.
Command:
aws budgets describe-subscribers-for-notification --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--max-results5
Output:
{ "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "example2@example.com" }, { "SubscriptionType": "EMAIL", "Address": "example@example.com" } ] }
-
For API details, see DescribeSubscribersForNotification
in Amazon CLI Command Reference.
-
The following code example shows how to use update-budget
.
- Amazon CLI
-
To replace a budget for a Cost and Usage budget
This example replaces a Cost and Usage budget with a new budget.
Command:
aws budgets update-budget --account-id
111122223333
--new-budgetfile://new-budget.json
new-budget.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" }
-
For API details, see UpdateBudget
in Amazon CLI Command Reference.
-
The following code example shows how to use update-notification
.
- Amazon CLI
-
To replace a notification for a Cost and Usage budget
This example replaces an 80% notification for a Cost and Usage budget with a 90% notification.
Command:
aws budgets update-notification --account-id
111122223333
--budget-name"Example Budget"
--old-notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--new-notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=90,ThresholdType=PERCENTAGE
-
For API details, see UpdateNotification
in Amazon CLI Command Reference.
-
The following code example shows how to use update-subscriber
.
- Amazon CLI
-
To replace a subscriber for a Cost and Usage budget
This example replaces the subscriber for a Cost and Usage budget.
Command:
aws budgets update-subscriber --account-id
111122223333
--budget-name"Example Budget"
--notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
--old-subscriberSubscriptionType=EMAIL,Address=example@example.com
--new-subscriberSubscriptionType=EMAIL,Address=example2@example.com
-
For API details, see UpdateSubscriber
in Amazon CLI Command Reference.
-