This tutorial shows how to get the total amount charged to your Amazon Web Services (AWS) account for a given time period. You can also use the command in conjunction with the date
command to quickly check your costs for the current month.
Open AWS Cloud Shell. The rest of the instructions on this page are for running inside Cloud Shell.
To get the total costs for any arbitrary time period (for which AWS still provides cost data), you can use the aws ce get-cost-and-usage
command. The example below provides the total cost for the time period January 1, 2021 to February 1, 2021.
$ aws ce get-cost-and-usage \
--time-period 'Start=2021-01-01,End=2021-02-01' \
--metrics 'UnblendedCost' \
--granularity 'MONTHLY' \
--query 'ResultsByTime[*].Total.[UnblendedCost]' \
--output 'table'
You can replace the Start
and End
dates (format: Year-Month-Day) in the command above with the time period that you're interested in.
The Start
date is included in the time period. The End
date is excluded (i.e., the time period includes all dates prior to, but not including End
). Thus to get the total cost for a particular month, you should set the End
date to the first day of the next month.
The example command above provides the Unblended Cost, which is what most users will be interested in. However, the command can also provide the Blended Cost. You can find more information on Unblended vs. Blended Costs here.
A quick way to check the total cost for the current month including today is to use the UNIX date
command built into Cloud Shell:
$ ( \
START_DATE=$(date +"%Y-%m-01"); \
END_DATE=$(date +"%Y-%m-01" -d "$DATE + 1 month"); \
aws ce get-cost-and-usage \
--time-period "Start=$START_DATE,End=$END_DATE" \
--metrics 'UnblendedCost' \
--granularity 'MONTHLY' \
--query 'ResultsByTime[*].Total.[UnblendedCost]' \
--output 'table' \
)