Exemple #1
0
func grabSecurityGroupNames(stub map[string]map[string]interface{}, ec2Client *ec2.Client) error {
	names := make(map[string]interface{})
	stub["SecurityGroupName"] = names

	securityGroupIds := []string{}
	nameForId := make(map[string]string)
	for name, id := range stub["SecurityGroup"] {
		securityGroupIds = append(securityGroupIds, id.(string))
		nameForId[id.(string)] = name
	}

	groups, err := ec2Client.DescribeSecurityGroups(
		&ec2.DescribeSecurityGroupsParameters{
			GroupIds: securityGroupIds,
		},
	)
	if err != nil {
		return err
	}

	for _, group := range groups {
		name := nameForId[group.GroupId]
		names[name] = group.GroupName
	}

	return nil
}