HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

View billing and cost management dashboard info with AWS CLI

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
dashboardinfowithbillingviewmanagementcliawsandcost

Problem

The aws web console under "Billing" (https://console.aws.amazon.com/billing/) shows "Month-to-Date Spend by Service" which breaks down costs incurred so far this month by each service that is in use by an account.

It also shows the "Spend Summary" which shows the recent monthly total incurred cost as well as this month's forecast.

Is there a way to retrieve this information using the AWS CLI?

Solution

yes it is, I made a lambda function that posted it to a slack channel.

This is the CLI reference ce = cost-explorer

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ce/index.html

I remember there was a tricky part and if I'm not mistaken the forecast would be from today to the end of the month, so as the days passed it would decrease. When I built my version we were doing a lot of cost optimizations so it was very deceiving hahaha

So if you want the cost forecast to match the dashboard, you have to get the summary + the forecast. Not something super tricky, just something to watch for.

Context

StackExchange DevOps Q#15002, answer score: 1

Revisions (0)

No revisions yet.