Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Use the following command to list the stopped instances.

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

share|improve this answer
    
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
add comment

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).

share|improve this answer
    
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
add comment

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

This will only provide youlist of stopped instances.

share|improve this answer
    
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
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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