Author: Rafael M. Koike
AWS ProServe
This script was created to support automatic parsing of Detailed Billing Records (DBR) to JSON format and send these documents directly to ElasticSearch or save it in a JSON file. It’s based on AWS boto3, Elasticsearch Python API and click CLI creation kit.
This project isn’t on PyPI yet. For installation you will need to clone
this repository and use setup.py
script to install it. For
requirements see the requirements/base.txt
file. Clone this
repository and install using plain python and the setup.py
script.
For example:
- This option just install the dbrparser but maybe you can use the job.sh from the repository to schedule the process in your cronjob
$ pip install git+https://github.com/awslabs/aws-detailed-billing-parser.git
- This option clone the repository from git to your instance and install
$ git clone https://github.com/awslabs/aws-detailed-billing-parser.git
$ cd aws-detailed-billing-parser
$ python setup.py install
Once installed run dbrparser
CLI with --help
option:
$ dbrparser --help
Tests still need to be written. But we have already introduced
py.test, tox for test run automation and flake8 to check
quality and style of the code. There are nice stubs for testing the CLI
command line. All you have to do is install tox and issue tox
in
the command line.
- Unzip (Extract the DBR from zip file);
- S3 (Copy the source file from S3 bucket to local folder to process);
- To be compatible with AWS Lambda the parser must run in max 5 min
and depending on the size of the file this won’t be possible, so we
will probably need to include a new option like, say
--max-rows
and every call to lambda will process a maximum of10000
rows for exemple. This may give us a previsibility that lambda will work in the correct timeframe; - Write more tests.
- Bugfix: the last commits broke the compatibility with Elasticsearch 2.3
This version added the compatibility of ES 2.x and 6.x using 2 different document types To use the solution with ES6.x you must add --es6 in the command line and the index name will be just "billing" The default is ES2.x to keep backward compatibility. (the index name will be: billing-<year>-<month>)
- Bugfix: RI and Spot coverage was returning incorrect results with Python 2.7 due to the default integer result from /
- Refactoring: analytics() function has been refactored to reduce the memory usage and avoid problems with huge DBR files
- BugFix: Python 3 has deprecated the parameter encoding in the json library and some functions
still have them. Removed the encoding paramter solved the incompatibility
- BugFix: Some running instances don't have the UsageType in the format: <Usage>:<InstanceType>
Than we need to check if the UsageType has ':' and return InstanceType or N/A
- Included Dynamic Template to new document fields be Not Analyzed
- Included support to AWS Signed V4 requests. If you are running the
program from an EC2 instance or from a computer that has installed
aws cli and configured with the correct credentials you just need to
include
--awsauth
parameter - Changed the split_keys function to pre_process and include extra
information based on the UsageType field Now you have:
- UsageItem with the options:
- On-Demand
- Reserved Instance
- Spot Instance
- InstanceType with only the instance name extracted from the UsageType
- UsageItem with the options:
- Changed requirements to support newer versions of boto3. (Due to some other softwares that need version 1.3.1 or higher, dbrparser is conflicting with other softwares)
- Bugfix of timeout when sending by bulk (Increased to 30 seconds)
- Project was completely restructured in order to create a proper
Python package called
awsdbrparser
and the CLI namedbrparser
; - In the CLI side,
argparse
was dropped in favor of Armin Ronacher’sclick
, allowing a better and easier CLI implementation; - Introduced option ‘–quiet’ for those who intent to schedule DBR parsing via cron jobs, for example;
- Introduced option ‘–fail-fast’ which will stop parsing execution in case of an expected parse error or other component error;
- Dropped own implementation of progress bar in favor of click’s progress bar, which includes a nice ETA (estimated time for acomplishment) calculation;
- When used as a library, parser execution can be parametrized through
awsdbrparser.config.Config
class instance. - Entire code was reviewed to match PEP8 compliance (with fewer
exceptions) through
flake8
.
- Added incremental updates with
--check
parameter (Now you can update the same file to the index without need to delete the index and reprocess the entirely file again); - Compatible with Elasticsearch 2.1 and above (Removed the
_timestamp
from mapping that has been deprecated from 2.0 and above); - Included elapsed time to evaluate the time to process the file.
- Filter of control messages (Stop the error in the end of processing);
- Verbose output of the processing;
- Progress bar;
- Output options (to file or directly to Elasticsearch);
- Elasticsearch mapping.
- Initial version.