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 installOnce installed run dbrparser CLI with --help option:
$ dbrparser --helpTests 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-rowsand every call to lambda will process a maximum of10000rows for exemple. This may give us a previsibility that lambda will work in the correct timeframe; - Write more tests.
- 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
--awsauthparameter - 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
awsdbrparserand the CLI namedbrparser; - In the CLI side,
argparsewas 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.Configclass instance. - Entire code was reviewed to match PEP8 compliance (with fewer
exceptions) through
flake8.
- Added incremental updates with
--checkparameter (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
_timestampfrom 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.