Esempi di Budget AWS con la AWS CLI - AWS Command Line Interface

Esempi di Budget AWS con la AWS CLI

Gli esempi di codice seguenti mostrano come eseguire azioni e implementare scenari comuni utilizzando la AWS Command Line Interface con Budget AWS.

Le operazioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un link al codice sorgente completo, dove è possibile trovare le istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Operazioni

L’esempio di codice seguente mostra come utilizzare create-budget.

AWS CLI

Come creare un budget di utilizzo e costi

Il comando seguente create-budget crea un budget di costi e utilizzo.

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

Contenuto di 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" }

Contenuto di notifications-with-subscribers.json.

[ { "Notification": { "ComparisonOperator": "GREATER_THAN", "NotificationType": "ACTUAL", "Threshold": 80, "ThresholdType": "PERCENTAGE" }, "Subscribers": [ { "Address": "example@example.com", "SubscriptionType": "EMAIL" } ] } ]
  • Per informazioni dettagliate sull’API, consulta CreateBudget in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare create-notification.

AWS CLI

Come creare una notifica per il budget di costi e utilizzo specificato

Questo esempio crea una notifica per il budget di costi e utilizzo specificato.

Comando:

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
  • Per informazioni dettagliate sull’API, consulta CreateNotification in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare create-subscriber.

AWS CLI

Come creare un abbonato per una notifica associata a un budget di costi e utilizzo

Questo esempio crea un abbonato per la notifica specificata.

Comando:

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
  • Per informazioni dettagliate sull’API, consulta CreateSubscriber in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare delete-budget.

AWS CLI

Come eliminare un budget di costi e utilizzo

Questo esempio elimina il budget di costi e utilizzo specificato.

Comando:

aws budgets delete-budget --account-id 111122223333 --budget-name "Example Budget"
  • Per informazioni dettagliate sull’API, consulta DeleteBudget in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare delete-notification.

AWS CLI

Come eliminare una notifica da un budget

In questo esempio viene eliminata la notifica specificata dal budget specificato.

Comando:

aws budgets delete-notification --account-id 111122223333 --budget-name "Example Budget" --notification NotificationType=ACTUAL,ComparisonOperator=GREATER_THAN,Threshold=80,ThresholdType=PERCENTAGE
  • Per informazioni dettagliate sull’API, consulta DeleteNotification in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare delete-subscriber.

AWS CLI

Come eliminare un abbonato da una notifica

In questo esempio viene eliminato l’abbonato specificato dalla notifica specificata.

Comando:

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
  • Per informazioni dettagliate sull’API, consulta DeleteSubscriber in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare describe-budget.

AWS CLI

Come recuperare un budget associato a un account

Questo esempio recupera il budget di costi e utilizzo specificato.

Comando:

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" ] } } }
  • Per informazioni dettagliate sull’API, consulta DescribeBudget in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare describe-budgets.

AWS CLI

Come recuperare i budget associati a un account

Questo esempio recupera i budget di costo e utilizzo per un account.

Comando:

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

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" ] } } ] }
  • Per informazioni dettagliate sull’API, consulta DescribeBudgets in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare describe-notifications-for-budget.

AWS CLI

Come recuperare le notifiche relative a un budget

Questo esempio recupera le notifiche relative a un budget di costi e utilizzo.

Comando:

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

Output:

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

L’esempio di codice seguente mostra come utilizzare describe-subscribers-for-notification.

AWS CLI

Come recuperare gli abbonati per una notifica relativa a un budget

Questo esempio recupera gli abbonati per una notifica relativa al budget di costi e utilizzo.

Comando:

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

Output:

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

L’esempio di codice seguente mostra come utilizzare update-budget.

AWS CLI

Come sostituire un budget con un budget di costi e utilizzo

Questo esempio sostituisce un budget di costi e utilizzo con un nuovo budget.

Comando:

aws budgets update-budget --account-id 111122223333 --new-budget file://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" }
  • Per informazioni dettagliate sull’API, consulta UpdateBudget in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare update-notification.

AWS CLI

Come sostituire una notifica per un budget di costi e utilizzo

Questo esempio sostituisce una notifica dell’80% per un budget di costi e utilizzo con una notifica del 90%.

Comando:

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
  • Per informazioni dettagliate sull’API, consulta UpdateNotification in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare update-subscriber.

AWS CLI

Come sostituire un abbonato con un budget di costi e utilizzo

Questo esempio sostituisce l’abbonato con un budget di costi e utilizzo.

Comando:

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
  • Per informazioni dettagliate sull’API, consulta UpdateSubscriber in AWS CLI Command Reference.