Skip to content

Instantly share code, notes, and snippets.

@chris
Last active April 15, 2024 22:10
Show Gist options
  • Save chris/da3f183007e27c7b33f6d11db08e2012 to your computer and use it in GitHub Desktop.
Save chris/da3f183007e27c7b33f6d11db08e2012 to your computer and use it in GitHub Desktop.
Basic AWS API Pagination example (with Cognito)
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
)
// create the AWS client - uses environment/profile for values
cognitoidentityprovider.NewFromConfig(config.LoadDefaultConfig(context.Background()))
// Create the API parameters (e.g. your use pool ID in this case)
lui := cognitoidentityprovider.ListUsersInput{UserPoolId: &yourUserPoolID}
// Create the paginator (check the result for nil, as it doesn't return an error)
p := cognitoidentityprovider.NewListUsersPaginator(client, &lui)
// Iterate with the paginator
for p.HasMorePages() {
// Get the next page of results
page, err := p.NextPage(context.Background())
// Get a batch of results
for _, u := range page.Users {
// do something with a user/result (`u`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment