Skip to content

Instantly share code, notes, and snippets.

@toritori0318
Created September 1, 2011 17:34
Show Gist options
  • Select an option

  • Save toritori0318/1186716 to your computer and use it in GitHub Desktop.

Select an option

Save toritori0318/1186716 to your computer and use it in GitHub Desktop.
AWS全リージョンの情報取得(perl版)
use strict;
use VM::EC2;
my $owner_id = $ENV{EC2_OWNER_ID} or die 'EC2_OWNER_ID is required.';
#my $owner_id = shift or die 'aws_status.pl <owner_id>';
my $ec2 = VM::EC2->new;
my @regions = $ec2->describe_regions();
for my $region (@regions) {
# region
print "region : $region\n";
$ec2->endpoint("https://" . $region->regionEndpoint ."/");
# instances
my @instances = $ec2->describe_instances();
if(scalar @instances > 0 ){
print " instances\n";
printf " %-15s %-15s %s \n", $_->instance_id, $_->tags->{Name}, $_->instanceState for @instances;
}
# images
my @images = $ec2->describe_images(-owner => $owner_id);
if(scalar @images > 0 ){
print " images\n";
printf " %-15s %-15s %s \n", $_->imageId, $_->tags->{Name}, $_->imageState for @images;
}
# volumes
my @volumes = $ec2->describe_volumes();
if(scalar @volumes > 0 ){
print " volumes\n";
printf " %-15s %-15s %-15s %s \n", $_->volumeId, $_->snapshotId, $_->tags->{Name}, $_->status for @volumes;
}
# snapshots
my @snapshots = $ec2->describe_snapshots(-owner => $owner_id);
if(scalar @snapshots > 0 ){
print " snapshots\n";
printf " %-15s %-15s %-15s %s \n", $_->snapshotId, $_->volumeId, $_->tags->{Name}, $_->status for @snapshots;
}
# Elastic Address
my @addresses = $ec2->describe_addresses();
if(scalar @addresses > 0 ){
print " addresses\n";
printf " %-15s %-15s %s \n", $_->publicIp, $_->allocationId, $_->instanceId for @addresses;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment