Created
February 14, 2013 01:36
-
-
Save lamanotrama/4949981 to your computer and use it in GitHub Desktop.
インスタンスのNameタグから、そのインスタンスに付いてるsecurity groupの名前を得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $ec2 = Net::Amazon::EC2->new( | |
AWSAccessKeyId => $config->{AWSAccessKeyId}, | |
SecretAccessKey => $config->{SecretAccessKey}, | |
region => $config->{region}, | |
) or die; | |
my ($instance) = | |
grep { | |
grep { $_->value eq $name } | |
grep { $_->key eq 'Name' } | |
@{ $_->tag_set || [] }; | |
} | |
map { $_->instances_set } | |
@{ $ec2->describe_instances }; | |
return () unless $instance; | |
my $group_set = $ec2->describe_instances( | |
InstanceId => [ $instance->instance_id ] | |
)->[0]->group_set; | |
my @sgs= | |
map { $_->group_name } | |
@{ $group_set }; | |
return @sgs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment