Difference between revisions of "Aws ce get-cost-and-usage"

From wikieduonline
Jump to navigation Jump to search
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ce/get-cost-and-usage.html
+
<code>[[aws ce]] get-cost-and-usage</code> <ref>https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ce/get-cost-and-usage.html</ref>
  
 
== Examples ==
 
== Examples ==
 +
 +
{{aws ce get-cost-and-usage example}}
 +
  
 
  [[aws ce]] get-cost-and-usage                                  \
 
  [[aws ce]] get-cost-and-usage                                  \
     --time-period 'Start=2021-01-01,End=2021-02-01'        \
+
     --time-period 'Start=2023-01-01,End=2023-11-30'        \
     --metrics    'UnblendedCost'                          \
+
     --metrics    '[[UnblendedCost]]'                          \
     --granularity 'MONTHLY'                                \
+
     --granularity 'DAILY'                                \
 
     --query      'ResultsByTime[*].Total.[UnblendedCost]' \
 
     --query      'ResultsByTime[*].Total.[UnblendedCost]' \
 
     --output      'table'
 
     --output      'table'
 +
  
 
Output:
 
Output:
Line 21: Line 25:
  
 
  aws ce get-cost-and-usage                                  \
 
  aws ce get-cost-and-usage                                  \
     --time-period 'Start=2021-01-01,End=2021-02-01'        \
+
     --time-period 'Start=2022-01-01,End=2022-05-01'        \
 
     --metrics    'UnblendedCost'                          \
 
     --metrics    'UnblendedCost'                          \
 
     --granularity 'MONTHLY'                                \
 
     --granularity 'MONTHLY'                                \
Line 28: Line 32:
 
     --filter      {"Dimensions": { "Key": "REGION", "Values": ["us-east-2"]}}
 
     --filter      {"Dimensions": { "Key": "REGION", "Values": ["us-east-2"]}}
  
 
+
  [[aws ce get-cost-and-usage]] --time-period Start=2022-09-01,End=2023-09-01 --granularity MONTHLY --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment --filter file://[[filters.json]]
 
 
 
 
  [[aws ce get-cost-and-usage]] --time-period Start=2020-06-01,End=2020-06-30 --granularity MONTHLY --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment --filter file://[[filters.json]]
 
  
 
Output:
 
Output:
Line 100: Line 101:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
== Errors ==
 +
An error occurred ([[ValidationException]]) when calling the GetCostAndUsage operation: start date is too old for daily granularity, max months for data available is 12 months
 +
 +
== Related ==
 +
* <code>[[aws list all]]</code>
 +
* <code>[[aws s3 ls]]</code>
  
 
== See also ==
 
== See also ==

Latest revision as of 11:09, 12 February 2024

aws ce get-cost-and-usage [1]

Examples[edit]

 aws ce get-cost-and-usage                                  \
    --time-period 'Start=2023-02-29,End=2024-02-29'        \
    --metrics     'UnblendedCost'                          \
    --granularity 'MONTHLY'                                \
    --query       'ResultsByTime[*].Total.[UnblendedCost]' \
    --output      'table'


aws ce get-cost-and-usage                                  \
    --time-period 'Start=2023-01-01,End=2023-11-30'        \
    --metrics     'UnblendedCost'                          \
    --granularity 'DAILY'                                \
    --query       'ResultsByTime[*].Total.[UnblendedCost]' \
    --output      'table'


Output:

-----------------------------
|      GetCostAndUsage      |
+------------------+--------+
|      Amount      | Unit   |
+------------------+--------+
|  15935.2793975583|  USD   |
+------------------+--------+
aws ce get-cost-and-usage                                  \
    --time-period 'Start=2022-01-01,End=2022-05-01'        \
    --metrics     'UnblendedCost'                          \
    --granularity 'MONTHLY'                                \
    --query       'ResultsByTime[*].Total.[UnblendedCost]' \
    --output      'table'                                  \
    --filter      {"Dimensions": { "Key": "REGION", "Values": ["us-east-2"]}}
aws ce get-cost-and-usage --time-period Start=2022-09-01,End=2023-09-01 --granularity MONTHLY --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment --filter file://filters.json

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"
                        }
                    }
                }
            ]
        }
    ]
}

Errors[edit]

An error occurred (ValidationException) when calling the GetCostAndUsage operation: start date is too old for daily granularity, max months for data available is 12 months

Related[edit]

See also[edit]

  • https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ce/get-cost-and-usage.html
  • Advertising: