Skip to content

Instantly share code, notes, and snippets.

@lamanotrama
Created February 14, 2013 01:36
Show Gist options
  • Save lamanotrama/4949981 to your computer and use it in GitHub Desktop.
Save lamanotrama/4949981 to your computer and use it in GitHub Desktop.
インスタンスのNameタグから、そのインスタンスに付いてるsecurity groupの名前を得
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