nagalikith / aws-billing-to-slack

Send a daily AWS cost report to a Slack channel of your choice.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWS Billing to Slack

image

Sends daily breakdowns of AWS costs to a Slack channel.

Install

  1. Install serverless, which I use to configure the AWS Lambda function that runs daily.

    npm install -g serverless
    
  2. Create an incoming webhook that will post to the channel of your choice on your Slack workspace. Grab the URL for use in the next step.

  3. Create the service on your local machine. cd to your directory and run this command. Replace path with the path name for the service and app name for the service.

    serverless create \
      --template-url="https://github.com/iandees/aws-billing-to-slack.git" \
      --path="app-aws-cost" \
      --name="app-aws-cost"
    
  4. Install pipenv

    pip install pipenv
    
  5. Install serverless python requirements

    serverless plugin install -n serverless-python-requirements
    
  6. Deploy the system into your AWS account, replacing the webhook URL below with the one you generated above.

    serverless deploy --stage="prod" --slack_url="https://hooks.slack.com/services/xxx/yyy/zzzz"
    

    You can also run it once to verify that it works:

    serverless invoke --function report_cost --slack_url="https://hooks.slack.com/services/xxx/yyy/zzzz"
    

Support for AWS Credits

If you have AWS credits on your account and want to see them taken into account on this report, head to your billing dashboard and note down the "Expiration Date", "Amount Remaining", and the "as of" date towards the bottom of the page. Add all three of these items to the command line when executing the deploy or invoke:

```
serverless deploy \
    --slack_url="https://hooks.slack.com/services/xxx/yyy/zzzz" \
    --credits_expire_date="mm/dd/yyyy" \
    --credits_remaining_date="mm/dd/yyyy" \
    --credits_remaining="xxx.xx"
```

Other Useful CLI Arguments Related to your AWS account

With none of the folling arguments passed (--aws_account, --aws_profile, --aws_region), sensible defaults are attempted to be retrieved. For example, boto3 is used to try and determine your AWS account alias if it exists, and if not your AWS account ID. Additionally, for your AWS profile the environment variable AWS_PROFILE is read and used if present, otherwise fallback to 'default'. Finally, for your AWS region the environment variables AWS_REGION, then AWS_DEFAULT_REGION are read and used if present, otherwise fallback to 'us-east-1' (N. Virginia). However, if you supply one of these arguments when executing the deploy or invoke command, then these values are taken and no defaults are attempted to be retrieved:

```
serverless deploy \
    --slack_url="https://hooks.slack.com/services/xxx/yyy/zzzz" \
    --aws_account="my custom account name" \
    --aws_profile="default" \
    --aws_region="eu-west-1"
```

Authors

About

Send a daily AWS cost report to a Slack channel of your choice.

License:MIT License


Languages

Language:Python 97.7%Language:Dockerfile 2.3%