Skip to content

clear-code/zulip-aws-usage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zulip-aws-usage

Programatically send AWS usage report to Zulip.

QuickStart

  1. Set up an AWS access key.

    $ aws configure
    $ cat ~/.aws/credentials
    [default]
    aws_access_key_id = xxx
    aws_secret_access_key = xxx
    $ cat ~/.aws/config
    [default]
    region = ap-northeast-1
    • If need, you can use multiple profiles.
    $ aws configure --profile bot
    $ cat ~/.aws/credentials
    [default]
    aws_access_key_id = xxx
    aws_secret_access_key = xxx
    [bot]
    aws_access_key_id = xxx
    aws_secret_access_key = xxx
  2. Prepare a bot on Zulip.

    • Visit "Settings > Personal > Bot" and create an "incoming webhook" bot.
  3. Set up your notification configuration.

    $ cp config.yaml.tmpl config.yaml
    $ vim config.yaml
  4. Run pip install and run report.py.

    $ python3 -m pip install -r requirments.txt
    $ python3 report.py
    • If you need to use multiple AWS profiles, you can use --aws-profile option to specify the profile.
    $ python3 report.py --aws-profile bot

HowTo Guides

How to send a test message

You can send reports to yoru private chat by setting zulip.type to private. See Zulip API documentation for details.

zulip:
  ...
  type: "private"
  to: "[email protected]"
  topic: ""
  ...

How to fix "Permission denied" error on AWS

You need AWSBudgetsReadOnlyAccess and AmazonEC2ReadOnlyAccess to fetch the AWS usage data.

Check your current permission policy on IAM > Users.

How to schedule bot execution

Install the service definition files:

$ mkdir -p ~/.config/systemd/user/
$ cp systemd/zulip-aws-usage.* ~/.config/systemd/user/

Fix the script path or options for the script in ExecStart:

$ vim ~/.config/systemd/user/zulip-aws-usage.service

Check if the service works:

$ systemctl start --user zulip-aws-usage.service

If it worked, enable the timer:

$ systemctl enable --now --user zulip-aws-usage.timer

You can check the execution schedule as follows:

$ systemctl list-timers --user

License

Copyright (C) 2022 Daijiro Fukuda <[email protected]>
Copyright (C) 2022 Fujimoto Seiji <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License v2.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

About

Programatically send AWS usage report to Zulip.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages