It is a repository that contains the entire project for cost management engine logic in aws lambda.
Job is responsible for automatically obtaining management costs and making them available on S3.
(files in config is only for glue jobs configurations DO NOT FORGET CHANGE VALUES IN THE FILES BEFORE EXECUTION!)
What is needed before running the script.
Libraries used in this project (included into dockerfile!):
- π Packages
- π s3fs
- π boto3
- π pandas
- π snowflake-connector-python
- π awslambdaric
- π cryptography
--SECRET_NAME: Name of the secret with connection informations.
β π Example: secret_test
--REGION_NAME: Name of region.
β π Example: us-east-1
--ENV: Cost environment to obtain.
β π Example: DEV|PRD
--FILE: Parameters file path.
β π Example: s3://utils/scripts/parameters.json
--OUTPUT_PATH: Output of csv path.
β π Example: s3://utils/costs
--PYTHONIOENCODING: Set default encoding.
β π Example: utf8
--SNOW_WAREHOUSE: Warehouse to connect in snowflake.
β π Example: DEV_COMMON_MONITORING
Parameters like ACCESS_KEY, SECRET_KEY, SNOW_USER and SNOW_PASS is in AWS sercret manager
To create the job:
- Copy the project files to a location on your local machine;
- Change the information you want in the code;
- Run the below code to build your image:
docker build -t <USER_ID>.dkr.ecr.<REGION>.amazonaws.com/<REPO_IN_ECR> .
β π Example: docker build -t 1234567890.dkr.ecr.us-east-1.amazonaws.com/costs .
- Run the below code to publish your image on ECR:
β docker push <USER_ID>.dkr.ecr.<REGION>.amazonaws.com/<REPO_IN_ECR>
β π Example: docker push 1234567890.dkr.ecr.us-east-1.amazonaws.com/costs
- If you get error "no basic auth credentials" to publish image, make sure if your docker config.json has the below informations:
{
"credsStore": "ecr-login"
}
- Create a lambda function with this image as template.
- Make sure that the lambda function has a sufficient timeout (5 minutes recommended).
- Make sure that the lambda function has a sufficient memory (512MB recommended).
Some examples of configuration files used in this script:
- JSON Parameters Estructure:
{
"fetch": {
"start_date": "2020-06-01",
"end_date": ""
},
"aws": {
"enable": true,
"tag_key": "project",
"multiply_factor_enable": false,
"multiply_factor_amount": 1,
"multiply_factor_unit": "USD"
},
"snowflake": {
"enable": true,
"account":"<*your-account*>"
"multiply_factor_enable": true,
"multiply_factor_amount": 3,
"multiply_factor_unit": "USD"
},
"databricks":{
"account_id": "",
"credentials_id": "",
"storage_configuration_id": ""
}
}
- Gabriel PraΓ§a - π» Developer