AWS scripts and tools
This is a very simple lambda script for rebooting EC2 instance when HTTP(s) site is unreachable or does not contain selected text.
When you create this Lambda script in AWS you should trigger it by CloudWatch Events trigger with Schedule expression set up for rate(1 hour) or whatever you like. For most scenarios it should run completely free of charge in free tier usage.
It is also needed to increase timeout for this script - recommended value is 10 minutes but might be lower.
I was solving issue that I wanted to know when my UPS lose and restore power. First idea was to use some kind of e-mail but it is very difficult to configure to pass your message through SPAM folder etc. Using SNS (Simple Notification Service) within AWS is so much more easier. You just use Python three liner to publish message to ARN queue and then SNS publish it to your e-mail, SMS or whatever of your choice.
This tools watches logs directory where are the S3 Logs files stored with Lambda script located in aws directory and when there is triggered S3 bucket event - ObjectCreated on directory where S3 logs are stored the lambda script creates the message in SQS (Simple Queue Service) and delete log file.
After that there is running SystemD daemon on Linux machine with MySQL installed called s3logs_daemon.py (stored in scripts directory) which check SQS queue for new logs and insert them into MySQL database.
Please be informed that there is no frontend - the main reason is that I find using PHPMyAdmin more universal and better because I can create directly SQL queries which I like.
some image tutorial is stored in imgs directory
- Clone repository to your directory
- Set-up S3 logs in directory you like
- Create lambda function (source file is stored in aws directory) which is triggered by CloudWatch event ObjectCreated on S3 Logs directory.
- Set-up SQS queue
- Wait few hours (S3 logs are created only every few hours not on every access)
- Check SQS queue that it contains messages
- Install MySQL, PhpMyAdmin, Apache
- Create database with initial structure (sql file is in the scripts directory)
- Install scripts and SystemD service files
- Start and enable SystemD service
Of course do not forget to change variables in various script files. Also the path where scripts should be installed is visible in the source files.