Programatically send AWS usage report to Zulip.
-
Set up an AWS access key.
- If you don't have
AWS CLI, then install it.
$ 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
- If you don't have
-
Prepare a bot on Zulip.
- Visit "Settings > Personal > Bot" and create an "incoming webhook" bot.
-
Set up your notification configuration.
$ cp config.yaml.tmpl config.yaml $ vim config.yaml
-
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-profileoption to specify the profile.
$ python3 report.py --aws-profile bot - If you need to use multiple AWS profiles, you can use
You can send reports to yoru private chat by setting zulip.type to private.
See Zulip API documentation for details.
zulip:
...
type: "private"
to: "my-name@example.com"
topic: ""
...You need AWSBudgetsReadOnlyAccess and AmazonEC2ReadOnlyAccess to fetch the AWS usage data.
Check your current permission policy on IAM > Users.
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.serviceCheck if the service works:
$ systemctl start --user zulip-aws-usage.serviceIf it worked, enable the timer:
$ systemctl enable --now --user zulip-aws-usage.timerYou can check the execution schedule as follows:
$ systemctl list-timers --userCopyright (C) 2022 Daijiro Fukuda <fukuda@clear-code.com>
Copyright (C) 2022 Fujimoto Seiji <fujimoto@clear-code.com>
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.