1

I have been experimenting around with ec2-describe-instances and ec2-describe-instance-status in the EC2 command line tools with the goal of starting stopped instances. However I cannot neatly list all stopped instances. ec2-describe-instance-status only lists running instances (unless I am doing something wrong).

Is there an easier way to list stopped instances than awk-ing the hell out of ec2-describe-instances?

4

Use the following command to list the stopped instances.

ec2-describe-instances --filter "instance-state-name=stopped"

  • Excellent! That's half the battle won! Having that pre-filter will make awk-ing the output easier anyway. Cheers for that! – Oldtowner Sep 12 '12 at 8:14
0

You can use a ruby script I've written for some purposes that uses the aws gem:

#!/usr/bin/ruby

require 'aws'

ec2 = AWS::EC2.new(
:access_key_id => 'AWS_KEY',
:secret_access_key => 'AWS_SECRET')

ec2.regions.each do |region|
 ec2.regions["#{region.name}"].instances.each do |line|
  if line.status.to_s=="stopped"
   puts("#{line}") #check docs for what exactly you need to output
  end
 end
end

You can modify it for your own purposes to get all the data you need. Just check the docs at https://github.com/grempe/amazon-ec2 (if I'm not wrong).

  • I would prefer if there was a stand alone solution that doesn't require additional libraries. Also, I'm not immediately familiar with Ruby, so that is another layer removed! Cheers for the link though, I now have a fall back :D – Oldtowner Sep 11 '12 at 16:58
0

ec2-describe-instances --filter "instance-state-name=stopped" | ec2-start-instances -

The "-" tells ec2-start-instances to read from stdin.

-1

ec2-describe-instance-status --filter "instance-state-name=stopped"

This will only provide youlist of stopped instances.

  • This maybe something about my setup that needs debugging, but ec2-describe-instance-status only lists running instances. Is this right? should it list stopped instances? – Oldtowner Sep 11 '12 at 16:49
  • no, it also lists stopped instances as well. try this command and see yourself – Farhan Sep 11 '12 at 16:50
  • I have run the command, and as I say, stopped instances are not listed, it does list all running though. With the filtered argument, nothing is returned. – Oldtowner Sep 11 '12 at 16:54
  • 1
    ec2-describe-instance-status only lists instances in the "Running" state. See docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/… – Matt Houser Sep 11 '12 at 17:22
  • 1
    Try ec2-describe-instances --filter "instance-state-name=stopped" – Matt Houser Sep 11 '12 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.