Giter VIP home page Giter VIP logo

aws-cost's Introduction

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 build 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.), filter using Expression and also change grouping. Warning, additional tags require second grouping to be LINKED_ACCOUNT. See here for possible values. Here is the config for example:

{
  "accounts": [
    {
      "name": "main production account",
      "id": "12313...9",
      "tags": {
          "environment": "prod",
          "project": "website"
      }
    }
  ],
  "filter": {
      "And": [
          {
              "Tags": {
                  "Key": "ENV",
                  "Values": ["PROD"]
              }
          },
          {
              "Tags": {
                  "Key": "Name",
                  "Values": ["APP1","APP2"]
              }
          }
      ]
  },
  "group": [
        {
            "group_id":"REGION",
            "label":"region"
        },
        {
            "group_id":"LINKED_ACCOUNT",
            "label":"account_id"
        }
    ],
   "tags":{
       "env":"prod",
       "apps":"app1_app2"
   }
}

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.

aws-cost's People

Contributors

sergkondr avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.