SSH to Auto Scaled EC2 instances

If you use Auto Scaling with AWS, the following script may come in handy.

Sometimes you just want to connect to a random auto scaled server or servers. Using this script you can simply run it once to get a random server or run it repeatedly to connect to all the servers in your auto scaling group.

I place the script at ~/bin/appserver and then run chmod +x ~/bin/appserver to make it executable.

It requires PHP and the AWS CLI to be installed – you will also need to have permission to run the aws ec2 describe-instances command.

Setup is simple. Just set the path to your private key, your SSH username and change the autoscaling group or groups you wish to connect to.

Laravel Cron Validator

As part of a tool I am currently creating I needed a way to validate user supplied cron patterns.

Laravel has plenty of built in validators including regex which I could have used, however I found creating the required regex pattern was complicated – and ugly. I wanted to just be able to specify the rule in the model validation rules with something simple like “cron_expression”.

Custom validation rules allow you to do this easily and in a much more tidy fashion.

Instead of writing the regex patterns required to detect cron patterns I decided to use the brilliant cron expression library to do the validation for me – all of the validation is already done and any PHP project that is dealing with cron expressions should already be using this parser as it seems to be the best out there by far.

Putting all of this together I came up with the laravel cron validator which I wrapped up as a service provider for ease of use.