Use DescribeCluster as ListCluster is a Paginated API

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-04-24 10:13:38 +02:00
parent ea6d35a927
commit f8bf0078aa
1 changed files with 5 additions and 8 deletions

View File

@ -2,8 +2,7 @@ package amazon
import (
"errors"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/sirupsen/logrus"
)
@ -40,13 +39,11 @@ func (c client) DeleteCluster() error {
func (c client) ClusterExists() (bool, error) {
logrus.Debug("Check if cluster was already created: ", c.Cluster)
clusters, err := c.ECS.ListClusters(nil)
clusters, err := c.ECS.DescribeClusters(&ecs.DescribeClustersInput{
Clusters: []*string{aws.String(c.Cluster)},
})
if err != nil {
return false, err
}
found := false
for _, arn := range clusters.ClusterArns {
found = found || strings.HasSuffix(*arn, "/"+c.Cluster)
}
return found, nil
return len(clusters.Clusters) > 0, nil
}