Giter VIP home page Giter VIP logo

aws-ec2-slackbot's Introduction

aws-ec2-slackbot

Simple bot I wrote to avoid having unecessary active instances on Amazon Web Services (AWS). It uses AWS CLI to check for active EC2 instances / EMR clusters and sends reminders via the Slack messaging app to the corresponding user.

Requirements:

  • Python 2.7
  • Slackclient Python module
  • Slack account / workspace
  • Slack API token (https://api.slack.com/)
  • Amazon Web Services (AWS) account
  • AWS Command Line Interface (CLI) configured

Configuration

Cloning the repository into your home folder:

cd ~/
git clone https://github.com/brdeleeuw/aws-ec2-slackbot

รŒf you don't have the Python Slackclient module:

pip install slackclient

Adjust slack_credentials_example.py file and add your auth token. Save as slack_credentials.py

Adjust user_info_example.py:

  • Add the username on your operating system
  • Add the names of your AWS profiles found in ~/.aws/config file
  • Add the keypair-username combinations as shown in the example.
  • Save as user_info.py.

To make the run_bot.py file executable, cd into the directory and make it executable:

cd ~aws-ec2-slackbot/src
chmod +x run_bot.py

Also, don't remove the #!/usr/bin/python shebang at the top of the script.

You may need to adjust the log_file_path variable in aws_functions.py to the directory where you cloned the repository to if you didn't choose the home directory.

Running automatically

To send reminders, we can have the file run in a cronjob.

crontab -e

Then add whenever you want the file to run. Example of a crontab entry to send a reminder at 16:30, 17:00 and 17:30 every day:

#min hour day-of-month  month  day-of-week  commannd
30    16        *         *        *         cd ~/aws-ec2-slackbot/src/ && /usr/bin/python ~/aws-ec2-slackbot/src/run_bot.py  >> ~/aws-ec2-slackbot/src/logs/run_bot_output.txt  2>&1
00    17        *         *        *         cd ~/aws-ec2-slackbot/src/ && /usr/bin/python ~/aws-ec2-slackbot/src/run_bot.py  >> ~/aws-ec2-slackbot/src/logs/run_bot_output.txt  2>&1
30    17        *         *        *         cd ~/aws-ec2-slackbot/src/ && /usr/bin/python ~/aws-ec2-slackbot/src/run_bot.py  >> ~/aws-ec2-slackbot/src/logs/run_bot_output.txt  2>&1

aws-ec2-slackbot's People

Stargazers

 avatar  avatar

Watchers

 avatar

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.