Code Monkey home page Code Monkey logo

python-aws-billing-athena's Introduction

Read AWS Billing Reports into AWS Athena with Python and AWS Lambda

This library is meant to help those who would like to read their AWS billing reports through Athena.

This can be done for different reasons: maybe you just want to easily read your billing data, or maybe you also want to visualize them and you don't like AWS Cost Explorer.

There are other ways to do exactly what I just described, but:

  • it's Python
  • it's all transparent: this guide tells you what permissions your lambda will need, and you won't have to give any more than that.

If you don't care about any of the above, I suggest you use the cloudformation provided in this blog post from AWS blog itself.

It basically produces the same result, with the difference that you won't have a lot of control over which function does what.

How to deploy

Well, it's actually super simple.

1. Activate billing reports

If you are searching for this tool, you probably have your AWS Billing Report enabled, but better safe than sorry:

The Detailed Billing Report with Resources and Tags can be activated from the preferences entry in the billing menu by ticking the appropriate option, like so:

Activate Billing

2. Create an Athena database to store all your billing information

Just create a Database using the wizard and keep the name handy.

3. Create an AWS role

Create a IAM role with read-write access to the billing bucket, as well as access to Athena.

4. Create a Lambda function

  • Using the wizard, just choose Author from scratch and then use the role you just created and python 3.6 runtime
  • Go into the settings and give it all the possible memory, as well as a timeout of at least 2 minutes
  • Set up a trigger for the billing bucket, and keep the default Object Created (All) setting. You don't need to necessarily use prefixes or suffixes, as the lambda has a regex check in it. But they don't hurt.

5. Personalize all the things!

Now you need to substitute the names of:

  • your billing bucket (something like s3://your-billing-bucket, the one you specified in step 1.)
  • the name of the "folder" where you want to save the unzipped and well ordered csv files (just a plain name, like for_athena)
  • the Athena db where the table will be created (the name of the db you created in step 2)

Just go into config.py and change the variables there!

6. Zip the scripts and upload

  • cd code
  • zip -r lambda.zip *

Now in the lambda dashboard choose "upload zip file", then upload the zip!

7. Test

You can set up test cases, or just duplicate one of the zips. Note that the file you pick should contain aws-billing-detailed-line-items-with-resources-and-tags : that one is the kind used by the script.

Then just check whether a folder has appeared with the name you specified. Also, the Athena table should appear within a minute or so!

python-aws-billing-athena's People

Contributors

lohackerchebonta 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.