Beispiel #1
0
// ListClusters will return a slice of ECS Clusters
func ListClusters(svc *ecs.ECS) ([]*string, error) {
	var clusters []*string

	// List clusters
	reqParams := &ecs.ListClustersInput{
		MaxResults: aws.Int64(100),
		NextToken:  aws.String(""),
	}

	for {
		resp, err := svc.ListClusters(reqParams)

		// Error check
		if err != nil {
			return nil, fmt.Errorf("ecs.ListClusters: %s", err.Error())
		}

		// Expand slice of clusters and append to our comprehensive list
		clusters = append(clusters, resp.ClusterArns...)

		// Cycle token
		if resp.NextToken != nil {
			reqParams.NextToken = resp.NextToken
		} else {
			// Kill loop ... out of clusters
			break
		}

	}

	return clusters, nil
}
Beispiel #2
0
// ListClusters List ECS clusters
func ListClusters(svc *ecs.ECS, maxResults *int64) (*ecs.ListClustersOutput, error) {
	params := &ecs.ListClustersInput{
		MaxResults: maxResults,
	}
	resp, err := svc.ListClusters(params)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
Beispiel #3
0
// findClusterArn finds a cluster's arn from a more human
// readable name
func findClusterArn(svc *ecs.ECS, clusterName string) (string, error) {
	params := &ecs.ListClustersInput{}
	clusters, err := svc.ListClusters(params)
	if err != nil {
		return "", err
	}
	for _, clusterId := range clusters.ClusterArns {
		var pattern string = `/` + clusterName + `$`
		matched, _ := regexp.MatchString(pattern, *clusterId)
		if matched {
			return *clusterId, nil
		}
	}
	return "", errors.New("Could not find cluster with name: " + clusterName)
}