Last active
April 1, 2022 23:01
-
-
Save dishbreak/ec36d9f85fd98f67ff42aa67df0d6219 to your computer and use it in GitHub Desktop.
Dealing with AWS API pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ecsiterator | |
import ( | |
"context" | |
"github.com/aws/aws-sdk-go-v2/aws" | |
"github.com/aws/aws-sdk-go-v2/service/ecs" | |
) | |
func GetContainerInstanceArnsForEcsCluster(e *ecs.Client, ecsClusterName string) ([]string) { | |
var nextToken *string | |
containerInstanceArns := make([]string, 0) | |
for keepGoing := true; keepGoing; { | |
if resp, err := e.ListContainerInstances(context.TODO(), &ecs.ListContainerInstancesInput{ | |
Cluster: aws.String(ecsClusterName), | |
NextToken: nextToken, | |
}); err != nil { | |
return nil, err | |
} else { | |
nextToken = resp.NextToken | |
containerInstanceArns = append(containerInstanceArns, resp.ContainerInstanceArns...) | |
} | |
keepGoing = nextToken != nil | |
} | |
return containerInstanceArns, nil | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment