-
-
Save israelb/4d6771e723e4ac492d77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'syslog' | |
require 'net/http' | |
require 'aws-sdk' | |
Syslog.open | |
AWS.config({ | |
:access_key_id => '<iam user key>', | |
:secret_access_key => '<iam user secret>' | |
}) | |
metadata_endpoint = 'http://169.254.169.254/latest/meta-data/' | |
instance_id = Net::HTTP.get( URI.parse( metadata_endpoint + 'instance-id' ) ) | |
auto_scaling = AWS::AutoScaling.new | |
auto_scaling.groups.each { |group| | |
instance = group.ec2_instances.filter('instance-state-name', 'running').first | |
if( instance.instance_id == instance_id ) | |
command = ARGV * ' ' | |
Syslog.alert( 'running cron on ' + instance_id + ': ' + command ) | |
`#{command}` | |
end | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source "/usr/local/rvm/scripts/rvm" | |
cd "$(dirname "$0")" | |
./aws_autoscaling_cron.rb "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Statement": [ | |
{ | |
"Action": [ | |
"autoscaling:DescribeAutoScalingGroups", | |
"autoscaling:DescribeAutoScalingInstances", | |
"ec2:DescribeInstanceAttribute", | |
"ec2:DescribeInstanceStatus", | |
"ec2:DescribeInstances" | |
], | |
"Effect": "Allow", | |
"Resource": [ | |
"*" | |
] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#run a command every day at midnight | |
0 0 * * * ubuntu /aws_autoscaling_cron.sh <command> <parameters> > /dev/null 2> /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment