There are more AWS SDK examples available in the AWS Doc SDK Examples
AWS Budgets examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with AWS 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.
- AWS CLI
-
To create a Cost and Usage budget
The following
create-budgetexample creates a Cost and Usage budget.aws budgets create-budget \ --account-id123456789012\ --budgetfile://budget.json\ --notifications-with-subscribersfile://notifications-with-subscribers.jsonContents 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" }This command produces no output.
Contents of
notifications-with-subscribers.json:[ { "Notification": { "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL", "Threshold": 80, "ThresholdType": "PERCENTAGE" }, "Subscribers": [ { "Address": "example@example.com", "SubscriptionType": "EMAIL" } ] } ]For more information, see Creating a budget in the AWS Cost Management User Guide.
-
For API details, see CreateBudget
in AWS CLI Command Reference.
-
The following code example shows how to use create-notification.
- AWS CLI
-
To create a notification for the specified Cost and Usage budget
The following
create-notificationexample creates a notification for the specified Cost and Usage budget.aws budgets create-notification \ --account-id123456789012\ --budget-name"Example Budget"\ --notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE\ --subscriberSubscriptionType=EMAIL,Address=example@example.comThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see CreateNotification
in AWS CLI Command Reference.
-
The following code example shows how to use create-subscriber.
- AWS CLI
-
To create a subscriber for a notification associated with a Cost and Usage budget
The following
create-subscriberexample creates a subscriber for the specified notification.aws budgets create-subscriber \ --account-id123456789012\ --budget-name"Example Budget"\ --notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE\ --subscriberSubscriptionType=EMAIL,Address=example@example.comThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see CreateSubscriber
in AWS CLI Command Reference.
-
The following code example shows how to use delete-budget.
- AWS CLI
-
To delete a Cost and Usage budget
The following
delete-budgetexample deletes the specified Cost and Usage budget.aws budgets delete-budget \ --account-id123456789012\ --budget-name"Example Budget"This command produces no output.
For more information, see Deleting a budget in the AWS Cost Management User Guide.
-
For API details, see DeleteBudget
in AWS CLI Command Reference.
-
The following code example shows how to use delete-notification.
- AWS CLI
-
To delete a notification from a budget
The following
delete-notificationexample deletes the specified notification from the specified budget.aws budgets delete-notification \ --account-id123456789012\ --budget-name"Example Budget"\ --notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGEThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see DeleteNotification
in AWS CLI Command Reference.
-
The following code example shows how to use delete-subscriber.
- AWS CLI
-
To delete a subscriber from a notification
The following
delete-subscriberexample deletes the specified subscriber from the specified notification.aws budgets delete-subscriber \ --account-id123456789012\ --budget-name"Example Budget"\ --notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE\ --subscriberSubscriptionType=EMAIL,Address=example@example.comThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see DeleteSubscriber
in AWS CLI Command Reference.
-
The following code example shows how to use describe-budget.
- AWS CLI
-
To retrieve a budget associated with an account
The following
describe-budgetexample retrieves the specified Cost and Usage budget.aws budgets describe-budget \ --account-id123456789012\ --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-west-2" ] } } }For more information, see Viewing your budgets in the AWS Cost Management User Guide.
-
For API details, see DescribeBudget
in AWS CLI Command Reference.
-
The following code example shows how to use describe-budgets.
- AWS CLI
-
To retrieve the budgets associated with an account
The following
describe-budgetsexample retrieves the Cost and Usage budgets for an account.aws budgets describe-budgets \ --account-id123456789012\ --max-results20Output:
{ "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-west-2" ] } } ] }For more information, see Viewing your budgets in the AWS Cost Management User Guide.
-
For API details, see DescribeBudgets
in AWS CLI Command Reference.
-
The following code example shows how to use describe-notifications-for-budget.
- AWS CLI
-
To retrieve the notifications for a budget
The following
describe-notifications-for-budgetexample retrieves the notifications for a Cost and Usage budget.aws budgets describe-notifications-for-budget \ --account-id123456789012\ --budget-name"Example Budget"\ --max-results5Output:
{ "Notifications": [ { "Threshold": 80.0, "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL" } ] }For more information, see Viewing your budgets in the AWS Cost Management User Guide.
-
For API details, see DescribeNotificationsForBudget
in AWS CLI Command Reference.
-
The following code example shows how to use describe-subscribers-for-notification.
- AWS CLI
-
To retrieve the subscribers for a budget notification
The following
describe-subscribers-for-notificationexample retrieves the subscribers for a Cost and Usage budget notification.aws budgets describe-subscribers-for-notification \ --account-id123456789012\ --budget-name"Example Budget"\ --notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE\ --max-results5Output:
{ "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "example2@example.com" }, { "SubscriptionType": "EMAIL", "Address": "example@example.com" } ] }For more information, see Viewing your budgets in the AWS Cost Management User Guide.
-
For API details, see DescribeSubscribersForNotification
in AWS CLI Command Reference.
-
The following code example shows how to use update-budget.
- AWS CLI
-
To replace a budget for a Cost and Usage budget
The following
update-budgetexample replaces a Cost and Usage budget with a new budget.aws budgets update-budget \ --account-id123456789012\ --new-budgetfile://new-budget.jsonContents of
new-budget.json:{ "BudgetLimit": { "Amount": "100", "Unit": "USD" }, "BudgetName": "Example Budget", "BudgetType": "COST", "CostFilters": { "AZ": [ "us-west-2" ] }, "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" }This command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see UpdateBudget
in AWS CLI Command Reference.
-
The following code example shows how to use update-notification.
- AWS CLI
-
To replace a notification for a Cost and Usage budget
The following
update-notificationexample replaces an 80% notification for a Cost and Usage budget with a 90% notification.aws budgets update-notification \ --account-id123456789012\ --budget-name"Example Budget"\ --old-notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE\ --new-notificationNotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=90,ThresholdType=PERCENTAGEThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see UpdateNotification
in AWS CLI Command Reference.
-
The following code example shows how to use update-subscriber.
- AWS CLI
-
To replace a subscriber for a Cost and Usage budget
The following
update-subscriberexample replaces the subscriber for a Cost and Usage budget.aws budgets update-subscriber \ --account-id123456789012\ --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.comThis command produces no output.
For more information, see Editing a budget in the AWS Cost Management User Guide.
-
For API details, see UpdateSubscriber
in AWS CLI Command Reference.
-