Request AWS ASGs in batches

Signed-off-by: Kierran McPherson <kierran.mcpherson@xero.com>
This commit is contained in:
Kierran McPherson 2018-11-10 11:02:34 +13:00 committed by Kierran McPherson
parent 8aa61bc983
commit 0be767a90a
1 changed files with 30 additions and 19 deletions

View File

@ -491,8 +491,10 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G
}
if len(asgNames) != 0 {
for i := 0; i < len(asgNames); i += 50 {
batch := asgNames[i:minInt(i+50, len(asgNames))]
request := &autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: asgNames,
AutoScalingGroupNames: batch,
}
err := c.Autoscaling().DescribeAutoScalingGroupsPages(request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool {
for _, asg := range p.AutoScalingGroups {
@ -512,12 +514,21 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G
if err != nil {
return nil, fmt.Errorf("error listing autoscaling groups: %v", err)
}
}
}
return asgs, nil
}
// Returns the minimum of two ints
func minInt(a int, b int) int {
if a < b {
return a
}
return b
}
// matchesAsgTags is used to filter an asg by tags
func matchesAsgTags(tags map[string]string, actual []*autoscaling.TagDescription) bool {
for k, v := range tags {