AWS Cost Explorer CLI demo – filtering costs by cost allocation tags

Here’s a quick example:

$ cat filter.json
{
  "Tags": {
    "Key": "role",
    "Values": ["webserver"]
  }
}

$ aws ce get-cost-and-usage --time-period Start=$(date +"%Y-%m-%d" --date="-24 hours"),End=$(date +"%Y-%m-%d") --granularity=DAILY  --metrics BlendedCost --filter file://filter.json

RESULTSBYTIME	True
TIMEPERIOD	2018-08-09	2018-08-08
BLENDEDCOST	22.30	USD

References:

http://blog.xi-group.com/2015/01/small-tip-how-to-use-aws-cli-filter-parameter/

https://medium.com/@nachomillangarcia/prometheus-alerts-for-aws-daily-costs-3374137d1371