awscost

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 7 Imported by: 0

README

AWS Cost (Golang)

GoDoc 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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommaNumber

func CommaNumber(n int) string

func Message

func Message(key string, args ...interface{}) string

Types

type Costs

type Costs struct {
	Total    float64
	Other    float64
	Services map[string]float64
	Date     string
}

func (Costs) FormatAsOutputReport

func (c Costs) FormatAsOutputReport() string

func (*Costs) SetDate

func (c *Costs) SetDate(dt time.Time)

type KV

type KV struct {
	Key   string
	Value float64
}

type KVList

type KVList []KV

func (KVList) Len

func (l KVList) Len() int

func (KVList) Less

func (l KVList) Less(i, j int) bool

func (KVList) Swap

func (l KVList) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL