-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminate_asg.rb
executable file
·44 lines (35 loc) · 1.21 KB
/
terminate_asg.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
require 'optparse'
require 'rubygems'
require 'aws-sdk'
options = {
'region' => 'us-west-2',
'standby' => 'true'
}
parser = OptionParser.new do |opts|
opts.banner = 'Usage: remove_asg_from_elb.rb -a ASG [-r REGION] [-x]'
opts.on("-a", "--asg ASG", "Name of the ASG to remove (required)") do |opt|
options['asg'] = opt
end
opts.on("-r", "--region REGION", "Name of the AWS region to use (default: #{options['region']})") do |opt|
options['region'] = opt
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end
# Parse options
parser.parse!
required_options = %w{asg}
required_options.each do |option|
if options[option].nil?
puts "Error required argument (#{option}) is missing."
puts parser.help
exit 1
end
end
auto_scaling = Aws::AutoScaling::Client.new(region: options['region'])
launch_configuration_name = auto_scaling.describe_auto_scaling_groups(auto_scaling_group_names: [options['asg']]).auto_scaling_groups[0].launch_configuration_name
auto_scaling.delete_auto_scaling_group(auto_scaling_group_name: options['asg'], force_delete: true)
auto_scaling.delete_launch_configuration(launch_configuration_name: launch_configuration_name)