Monday, November 21, 2016

List your AWS EC2 instances, show the size

#!/home/matt_feenstra/.rvm/rubies/ruby-2.3.1/bin/ruby

puts 'Querying AWS command line..'

instanceids = Array.new
instancetypes = Array.new

output = Array.new
system('aws ec2 describe-instances >output.txt')
rawfile = File.open('output.txt', 'r')
rawfile.each do |l|
        output.push(l)
end

i = 0
output.each do |line|

        if line =~ /InstanceId\": \"(i-........)\",/ then
                instanceids[i] = $1
                print "InstanceID: #{instanceids[i]} "

                # find the next occurance of instancetype and break out
                subarray = output[i+1..output.length]

                subarray.each do |info|
                        if info =~ /InstanceType\": \"(.*)\",/ then
                                instancetypes[i] = $1
                                puts "Type: #{instancetypes[i]}"
                                break
                        end
                end
        end
        i += 1
end

1 comment:

  1. Thank a lot for this post that was very interesting. Keep posting like those amazing posts, this is really awesome :) Thank you for sharing wonderful information with us to get some idea about it.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    oracle online training

    hadoop training in chennai

    hadoop training in bangalore


    ReplyDelete