Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

jetbrains-infra/aws-cost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-cost Go Report Card Pulls

This utility gets AWS billing data from AWS Cost-Explorer and return it as an influx line protocol that can be imported by telegraf

TL;DR - Docker example

Docker image is located here.

$ docker run -it --rm \
  -e AWS_ACCESS_KEY_ID=AKI... \
  -e AWS_SECRET_KEY=9eg... \
  -v $(pwd):/app/config \
  jetbrainsinfra/aws-cost

Build

$ go biuld main.go

Use

At first you have to ensure, your AWS credentials have the following permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "ce:GetReservationUtilization",
                "ce:GetDimensionValues",
                "ce:GetCostAndUsage",
                "ce:GetTags"
            ],
            "Resource": "*"
        }
    ]
}

AWS Key ID and Secret ID may be taken from environment variables or from parameters of command line:

$ export AWS_ACCESS_KEY_ID=AKI...
$ export AWS_SECRET_KEY=9eg...
$ ./aws-cost

or:

$ ./aws-cost -key-id AKI... -secret 9eg... 

By default will be used yesterday as date, but you can specify date with -date parameter(YYYY-MM-DD format):

./aws-cost -date 2019-02-10
aws-cost,account_id=25***9,service_name=EC2_-_Other cost=1.1900133074 1549756800000000000
aws-cost,account_id=25***9,service_name=Amazon_Elastic_Compute_Cloud_-_Compute cost=15.1200098849 1549756800000000000
aws-cost,account_id=25***9,service_name=AmazonCloudWatch cost=0.15 1549756800000000000

Telegraf input plugin settings:

[[inputs.file]]
  files = ["/tmp/aws-cost"]
  data_format = "influx"

And run:

./aws-cost -date 2019-02-10 >> /tmp/aws-cost
./aws-cost -date 2019-02-11 >> /tmp/aws-cost
./aws-cost -date 2019-02-12 >> /tmp/aws-cost

Tags

You can use additional tags for your account. The idea of this feature is using different accounts in same project. Here is the config for example:

{
  "accounts": [
    {
      "name": "main production account",
      "id": "12313...9",
      "tags": {
          "environment": "prod",
          "project": "website"
      }
    }
  ]
}

And run:

./aws-cost -config aws-cost.json -exact
aws-cost,account_id=12313...9,account_name=main,service_name=EC2_-_Other,environment=prod,project=website cost=1.1900133074 1549756800000000000
aws-cost,account_id=12313...9,account_name=main,service_name=Amazon_Elastic_Compute_Cloud_-_Compute,environment=prod,project=website cost=15.1200098849 1549756800000000000
aws-cost,account_id=12313...9,account_name=main,service_name=AmazonCloudWatch,environment=prod,project=website cost=0.15 1549756800000000000

Also, it's not required to use flag -exact with -config but with -exact you will get only accouts that exists in aws-cost.json.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published