Questa documentazione è valida AWS CLI solo per la versione 1. Per la documentazione relativa alla versione 2 di AWS CLI, consulta la Guida per l'utente della versione 2.
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Esempi di utilizzo del servizio Cost Explorer AWS CLI
I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando il servizio AWS Command Line Interface with Cost Explorer.
Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le azioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.
Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.
Argomenti
Azioni
Il seguente esempio di codice mostra come utilizzareget-cost-and-usage.
- AWS CLI
-
Come recuperare l’utilizzo S3 di un account per il mese di settembre 2017
L’esempio
get-cost-and-usageseguente recupera l’utilizzo di S3 di un account per il mese di settembre 2017.aws ce get-cost-and-usage \ --time-periodStart=2017-09-01,End=2017-10-01\ --granularityMONTHLY\ --metrics"BlendedCost""UnblendedCost""UsageQuantity"\ --group-byType=DIMENSION,Key=SERVICEType=TAG,Key=Environment\ --filterfile://filters.jsonContenuto di
filters.json:{ "Dimensions": { "Key": "SERVICE", "Values": [ "Amazon Simple Storage Service" ] } }Output:
{ "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" } } } ] } ] }-
Per i dettagli sull'API, consulta GetCostAndUsage AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come utilizzareget-dimension-values.
- AWS CLI
-
Come recuperare i tag della dimensione SERVICE, con il valore “Elastic”
Questo esempio recupera i tag per la dimensione SERVICE, con il valore “Elastic” dal 1° gennaio 2017 al 18 maggio 2017.
Comando:
aws ce get-dimension-values --search-stringElastic--time-periodStart=2017-01-01,End=2017-05-18--dimensionSERVICEOutput:
{ "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 }-
Per i dettagli sull'API, consulta GetDimensionValues AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come utilizzareget-reservation-coverage.
- AWS CLI
-
Per recuperare la copertura delle prenotazioni per le istanze EC2 t2.nano nella regione us-east-1
Questo esempio recupera la copertura delle prenotazioni per le istanze EC2 t2.nano nella regione us-east-1 per luglio-settembre 2017.
Comando:
aws ce get-reservation-coverage --time-periodStart=2017-07-01,End=2017-10-01--group-byType=Dimension,Key=REGION--filterfile://filters.jsonfilters.json:
{ "And": [ { "Dimensions": { "Key": "INSTANCE_TYPE", "Values": [ "t2.nano" ] }, "Dimensions": { "Key": "REGION", "Values": [ "us-east-1" ] } } ] }Output:
{ "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 }-
Per i dettagli sull'API, consulta Command Reference. GetReservationCoverage
AWS CLI
-
Il seguente esempio di codice mostra come utilizzareget-reservation-purchase-recommendation.
- AWS CLI
-
Per recuperare i consigli di prenotazione per Partial Upfront EC2 RIs con un periodo di tre anni
L'
get-reservation-purchase-recommendationesempio seguente recupera i consigli per le EC2 istanze Partial Upfront con una durata di tre anni, in base agli ultimi 60 giorni di utilizzo. EC2aws ce get-reservation-purchase-recommendation \ --service"Amazon Redshift"\ --lookback-period-in-daysSIXTY_DAYS\ --term-in-yearsTHREE_YEARS\ --payment-optionPARTIAL_UPFRONTOutput:
{ "Recommendations": [], "Metadata": { "GenerationTimestamp": "2018-08-08T15:20:57Z", "RecommendationId": "00d59dde-a1ad-473f-8ff2-iexample3330b" } }-
Per i dettagli sull'API, consulta GetReservationPurchaseRecommendation
Command Reference.AWS CLI
-
Il seguente esempio di codice mostra come utilizzareget-reservation-utilization.
- AWS CLI
-
Come concedere l’autorizzazione a recuperare l’utilizzo della prenotazione per l’account
L’esempio
get-reservation-utilizationseguente recupera l’utilizzo delle istanze riservate per tutti i tipi di istanza t2.nano dal giorno 01-03-2018 al giorno 01-08-2018 per l’account.aws ce get-reservation-utilization \ --time-periodStart=2018-03-01,End=2018-08-01\ --filterfile://filters.jsonContenuto di
filters.json:{ "Dimensions": { "Key": "INSTANCE_TYPE", "Values": [ "t2.nano" ] } }Output:
{ "Total": { "TotalAmortizedFee": "0", "UtilizationPercentage": "0", "PurchasedHours": "0", "NetRISavings": "0", "TotalActualHours": "0", "AmortizedRecurringFee": "0", "UnusedHours": "0", "TotalPotentialRISavings": "0", "OnDemandCostOfRIHoursUsed": "0", "AmortizedUpfrontFee": "0" }, "UtilizationsByTime": [] }-
Per i dettagli sull'API, consulta GetReservationUtilization AWS CLI
Command Reference.
-
Il seguente esempio di codice mostra come utilizzareget-tags.
- AWS CLI
-
Come recuperare chiavi e valori per un tag di allocazione dei costi
Questo esempio recupera tutti i tag di allocazione dei costi con la chiave “Project” e un valore che contiene “secretProject”.
Comando:
aws ce get-tags --search-stringsecretProject--time-periodStart=2017-01-01,End=2017-05-18--tag-keyProjectOutput:
{ "ReturnSize": 2, "Tags": [ "secretProject1", "secretProject2" ], "TotalSize": 2 }-
Per i dettagli sull'API, consulta GetTags AWS CLI
Command Reference.
-