Skip to content

Commit d29ca03

Browse files
Add - implement additional AWS cost retrieval functions for current and last month
1 parent f252d84 commit d29ca03

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

services/aws_cost.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,31 @@ function aws_cost_list_months_later() {
1919
--time-period "Start=$(date -d "${months} months ago" +%Y-%m-01),End=$(date -d "$(date +%Y-%m-01) -1 day" +%Y-%m-%d)" \
2020
--granularity MONTHLY --metrics "UnblendedCost"
2121
}
22+
23+
function aws_cost_get_current_month() {
24+
aws ce get-cost-and-usage \
25+
--time-period "Start=$(date +%Y-%m-01),End=$(date +%Y-%m-%d)" \
26+
--granularity MONTHLY --metrics "UnblendedCost"
27+
}
28+
29+
function aws_cost_get_last_month() {
30+
aws ce get-cost-and-usage \
31+
--time-period "Start=$(date -d "$(date +%Y-%m-01) -1 month" +%Y-%m-01),End=$(date -d "$(date +%Y-%m-01) -1 day" +%Y-%m-%d)" \
32+
--granularity MONTHLY --metrics "UnblendedCost"
33+
}
34+
35+
function aws_cost_get_service_cost_current_month() {
36+
aws ce get-cost-and-usage \
37+
--time-period Start=$(date +%Y-%m-01),End=$(date -d "+1 day" +%Y-%m-%d) \
38+
--granularity MONTHLY \
39+
--metrics "UnblendedCost" \
40+
--group-by Type=DIMENSION,Key=SERVICE \
41+
--output table
42+
}
43+
44+
function aws_cost_get_last_7_days() {
45+
aws ce get-cost-and-usage \
46+
--time-period "Start=$(date -d "7 days ago" +%Y-%m-%d),End=$(date +%Y-%m-%d)" \
47+
--granularity DAILY --metrics "UnblendedCost" \
48+
--output table
49+
}

0 commit comments

Comments
 (0)