EC2 Shutdown Script (perl)

 
#!/usr/bin/perl

use Net::Amazon::EC2;
my $ec2 = Net::Amazon::EC2->new(
AWSAccessKeyId => 'XXXX',
SecretAccessKey => 'XXXX'

);

my $running_instances = $ec2->describe_instances;

foreach my $reservation (@$running_instances) {

foreach my $instance ($reservation->instances_set) {

my $instance_id = $instance->instance_id;

my $result = $ec2->terminate_instances(InstanceId => $instance_id);

print "terminating" . $instance_id . "\n";

}

}

Alternate method in bash:

    #!/bin/bash

    export JAVA_HOME=/usr
    export EC2_HOME=/opt/ec2/tools
    export EC2_PRIVATE_KEY=/root/ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem
    export EC2_CERT=/root/ec2/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem

    echo "Terminating Origin Server..."
    if test -f /root/ec2/origin.iid
    then
    date >> /root/term.log

    /opt/ec2/tools/bin/ec2-terminate-instances `cat /root/ec2/origin.iid` >> /root/term.log
    else
    echo "Instance ID not found!"
    fi
Info
Date Posted: 18 Nov 2009 @ 4:21 PM
Last Modified: 18 Nov 2009 @ 04:25 PM
Posted By: Ian Beyer
 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 Last 50 Posts
 Back
Change Theme...
  • Users » 3
  • Posts/Pages » 116
  • Comments » 126
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About the geek



    No Child Pages.

Airplanes



    No Child Pages.

Books



    No Child Pages.