Created
January 10, 2021 12:23
-
-
Save katzefudder/0c57a9300b0f0718b88f46539f9ae446 to your computer and use it in GitHub Desktop.
fetch the last months' costs from AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# displays the last month's costs in USD for tagged resources | |
# https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html | |
# FIRST=$(date --date="$(date +'%Y-%m-01') - 1 month" +%s) # date on general Linux distributions | |
# LAST=$(date --date="$(date +'%Y-%m-01') - 1 second" +%s) | |
PROJECT=del2 | |
FIRST=$(date -v1d -v-1m +%Y-%m-%d) # date on Mac OS X | |
LAST=$(date -v1d -v-1d +%Y-%m-%d) | |
aws ce get-cost-and-usage --time-period Start=$FIRST,End=$LAST --granularity=MONTHLY --metrics BlendedCost --filter '{"Tags": {"Key": "Project","Values": ["'$PROJECT'"]}}' | jq -r '.ResultsByTime[].Total.BlendedCost.Amount' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment