Skip to content

evalphobia/awscost

Repository files navigation

AWS Cost (Golang)

GoDoc License: MIT Release Build Status Codecov Coverage Go Report Card Code Climate BCH compliance

awscost is library to get AWS estimate billing costs. This library probides two ways to get costs.

  • ClowdWatch API
  • CostExplorer API

Quick Usage

import (
	"fmt"
	"time"

	"github.com/evalphobia/awscost/costexplorer"
)

func main() {
	endDate := time.Now().AddDate(0, 0, -1)

	// costs, err := cloudwatch.FetchDailyCost(endDate)
	costs, err := costexplorer.FetchDailyCost(endDate)
	if err != nil {
		return panic(err)
	}

	// set date to show it on the report
	costs.SetDate(endDate)
	text := costs.FormatAsOutputReport()

	// show cost data
	fmt.Println(text)

	// post cost data to slack channel
	err = sendCostToSlack(text)
	if err != nil {
		return panic(err)
	}
}

Environment variables

Name Description
AWSCOST_LANG Supported languages are en, ja. See the language file