Giter Site home page Giter Site logo

cost-reporter's Introduction

Cost Reporter

A lambda which sends a daily cost and trend report to slack. It helps with one of the three FinOps phases: Inform. It can send you a report every day / only when cost increases / only when cost breached a threshold depending on your configuration.

Helpful to keep an eye in new projects when the architecture changes quickly, but also for existing projects if you want to keep a close eye on cost.

Example:

Configuration

The following settings can be configured:

  • Title: The title for the cost report (i.e.: "Project: XYZ")
  • Days: The days to report (i.e. 10)
  • MinDailyCost: The minimal daily cost required to trigger a report in $ (i.e. 10)
  • OnlyNotifyOnIncrease: Whether to send a report only when the cost increased from yesterday to today
  • TargetChannel: The target channel (i.e. "#costoptimization")

Deployment

Prerequisites:

  • AWS SAM CLI
  • A slack token for the lambda (xoxx-....) with the permission to write files and send messages
  • A SecureString SSM Parameter for the Slack token: /cost-reporter/slack-token

How to deploy:

sam build --use-container
sam deploy --guided

cost-reporter's People

Contributors

flyck avatar nfriede avatar

Stargazers

Naresh Kumar avatar Isaac avatar  avatar Matthew Hembree avatar Naman Sharma avatar hndrk avatar  avatar Victor GRENU avatar Drew Dresser avatar David Hodge avatar EshBiz avatar Sadra Yahyapour avatar Adit Modi avatar Bob Benson avatar Kris Kumler avatar Thomas Labarussias avatar  avatar Eduardo Rabelo avatar  avatar  avatar Vincent Lee avatar  avatar Ahmed Qazi Muhammad Jamil avatar Mohammed Almusaddar avatar Hassan Murtaza avatar Ari Palo avatar Moataz Nabil avatar David Krohn avatar

Watchers

James Cloos avatar Nemanja Mitić avatar Maik Schmidt avatar zehsor avatar Mohammed Almusaddar avatar Alexey Mikhailov avatar Luka Vujić  avatar Aleksandar Babic avatar Djordje Spasojevic avatar  avatar Yassine Berrada Touati avatar

Forkers

flyck

cost-reporter's Issues

Fix and improve flake8 findings

Running flake8 cost-reporter results in

cost-reporter/tests/test_lambda_function.py:39:63: W292 no newline at end of file
cost-reporter/src/stacked_bar.py:34:19: F821 undefined name 'previous_bar'
cost-reporter/src/stacked_bar.py:35:37: F821 undefined name 'previous_bar'
cost-reporter/src/stacked_bar.py:39:9: F841 local variable 'previous_bar' is assigned to but never used

Also remove the ignored findings in the .flake8 file

ignore = E221, E251, E266

This will result in

cost-reporter/src/slack_sender.py:19:70: E251 unexpected spaces around keyword / parameter equals
cost-reporter/src/slack_sender.py:19:72: E251 unexpected spaces around keyword / parameter equals

Improve SAM template

  1. Remove the NoEcho property, because it is no secret, which SSM Parameter you use. Also add the Description property to explain, what it does.

    SlackTokenParameterName:
    Type: String
    Default: "/cost-reporter/slack-token"
    NoEcho: true

  2. Those types are Number

    Days:
    Type: String
    Default: 10
    Description: "The amount of days to include in the report"
    MinDailyCost:
    Type: String
    Default: 0
    Description: "The minimal daily cost to trigger a report"

  3. If this parameter is supposed to be of type boolean, then also enforce it

    OnlyNotifyOnIncrease:
    Type: String
    Default: true
    Description: "Whether to only notify if cost increased within the last day"

  OnlyNotifyOnIncrease:
    Type: String
    AllowedValues: 
      - "true"
      - "false"
    Default: "true"
    Description: "Whether to only notify if cost increased within the last day"
  1. Instead of adding the logs permissions
    -
    Sid: "Logging"
    Effect: "Allow"
    Action:
    - "logs:CreateLogGroup"
    - "logs:CreateLogStream"
    - "logs:PutLogEvents"
    Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*"

    just assign the AWS managed policy arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

Using A Test Runner

Simply use a test runner to access the project-level tests easier and implement the #15 issue easier.

Improve stacked_bar.py

  1. By PEP8 convention constants are written in all capital letters

    yellow = "#fed919"
    cyan = "#2db2a1"
    pink = "#ff6f61"
    magenta = "#a41d53"
    purple = "#6a45ce"
    light_green = "#3ecc54"
    dark_green = "#2db2a1"

  2. To save time with list conversion this

    first_key = list(all_bars.keys())[0]
    days = len(all_bars[first_key])

    can be written as

days = next(iter(all_bars.values()))

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.