Skip to content

Instantly share code, notes, and snippets.

@trlinkin
Created May 3, 2014 15:03
Show Gist options
  • Save trlinkin/e452440f9fbc72a7a6af to your computer and use it in GitHub Desktop.
Save trlinkin/e452440f9fbc72a7a6af to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
require 'aws-sdk'
config_file = File.join(File.dirname(__FILE__),"config.yml")
config = YAML.load(File.read(config_file))
AWS.config(config)
sqs = AWS::SQS.new
queue = sqs.queues[config['queue_url']]
queue.poll do |msg|
sns = msg.as_sns_message.body_message_as_h
if sns['Event'] == 'autoscaling:EC2_INSTANCE_TERMINATE'
%x"puppet cert clean #{sns['EC2InstanceId']}.aws"
%x"puppet node deactivate #{sns['EC2InstanceId']}.aws"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment