django-aws-billing

AWS Billing for Django


License
MIT
Install
pip install django-aws-billing==0.2.6

Documentation

Bezos is a Hustler

django-aws-billing

Django AWS Usage/Billing Package. Work in Progress.

  • Version: 0.2.6
  • Status: Working!

Maps items from CSVs in the AWS programmatic billing access reports to a BillingRecord model in Django, allowing billing queries to be processed via the Django ORM. Also provides some convenience methods to calculate costs for specific resources.

Set up

  1. First you need to set up Programmatic Billing Access and "detailed billing reporting with resources and tags" from your billing preferences page. This also means making a bucket to store the output in (those bastards, charging us to host our own billing data!), and setting up an appropriate policy for that bucket.

  2. Wait an hour for your first usage report to be generated. 😴

  3. Install django-aws-billing:

    pip install django-aws-billing
  4. Set your AWS credentials in your Django settings:

    AWS_ACCESS_KEY = 'AKDERPDERPDERPDERPDERP'
    AWS_SECRET_ACCESS_KEY = 'iL+HERPHERPHERPHERPHERPHERPSQUIRT'
    AWS_BILLING_BUCKET = 'your-aws-billing-info-bucket-name'
    AWS_ACCOUNT_ID = '1234-5679-0000' # Find this number from your AWS Manage Account page: https://portal.aws.amazon.com/gp/aws/manageYourAccount
  5. Add 'aws_billing' to your INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'aws_billing',
        ...
     )
  6. Run syncdb:

    python manage.py syncdb
  7. Run the billing command:

    python manage.py process_aws_billing
  8. You can then see the costs with:

    python manage.py aws_costs

Programmatic Usage

  1. Import it and call it!

    from aws_billing import aws_billing
    aws_billing.get_cost_for_resource('your-resource-name') # 12.002415
    aws_billing.get_total_cost() # 42.001234
    aws_billing.get_all_costs_by_resource() # {'your-resource-name': 12.002415, 'your-other-resource-name': 29.998819}

Hooray!

TODO:

  • Hopefully, this package will also include utilities to create nice little javascript charts.
  • Something something timezones. And date ranges on the utilities.
  • Tests
  • Your idea here? The future is unwritten..

Issues welcomed, patches thanked, stars appreciated.