Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list_shards paginator broken for 1000+ shards #2009

Open
slydon opened this issue Mar 30, 2020 · 4 comments
Open

list_shards paginator broken for 1000+ shards #2009

slydon opened this issue Mar 30, 2020 · 4 comments
Labels
bug This issue is a confirmed bug. kinesis p3 This is a minor priority issue paginator

Comments

@slydon
Copy link

slydon commented Mar 30, 2020

When using the paginator in list_shards for a stream with over 1000 shards an exception is thrown because the list_shards API expects the StreamName to not be set when specifying the NextToken parameter.

This is related to #1462 (comment)

@swetashre swetashre self-assigned this Mar 31, 2020
@swetashre
Copy link
Contributor

@slydon - Thank you for your post. I am not able to reproduce the issue. The comment you linked does not say anything about the exact error. Can you please provide me code sample you are using with the exact error you are getting ?

This is the documentation on how to use paginator with list_shards api:
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/kinesis.html#Kinesis.Paginator.ListShards

@swetashre swetashre added guidance Question that needs advice or information. closing-soon labels Apr 1, 2020
@slydon
Copy link
Author

slydon commented Apr 1, 2020

The error is:

botocore.errorfactory.InvalidArgumentException: An error occurred (InvalidArgumentException) when calling the ListShards operation: NextToken and StreamName cannot be provided together.

The code sample is:

import boto3
k = boto3.client('kinesis')
ls_p = k.get_paginator('list_shards')
len([s for p in ls_p.paginate(StreamName='large') for s in p.get('Shards', [])])

How did you try to reproduce this? If you are using kinesalite it doesn't implement this functionality correctly. https://github.com/mhart/kinesalite/blob/master/actions/listShards.js#L12

@no-response no-response bot removed the closing-soon label Apr 1, 2020
@swetashre
Copy link
Contributor

@slydon - Sorry i have directly called the paginator with StartingToken that's why did not able to reproduce the issue. But now i am able to reproduce the issue with the below code:

paginator = kinesis.get_paginator("list_shards").paginate(StreamName="test-stream", PaginationConfig={"PageSize": 1})

for page in paginator:
      print(page)

Marking this as bug.

@swetashre swetashre added bug This issue is a confirmed bug. paginator and removed guidance Question that needs advice or information. labels Apr 3, 2020
@bbayles
Copy link

bbayles commented Jun 16, 2020

I ran into this issue also.

Here is a code that can be used until the problem is fixed:

def list_shards(kinesis_client, stream_name):
    all_shards = []
    kwargs = {'StreamName': stream_name}
    while True:
        resp = kinesis_client.list_shards(**kwargs)
        for shard in resp['Shards']:
            all_shards.append(shard)

        next_token = resp.get('NextToken')
        if next_token:
            kwargs = {'NextToken': next_token}
        else:
            break
    
    return {'Shards': all_shards}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. kinesis p3 This is a minor priority issue paginator
Projects
None yet
Development

No branches or pull requests

6 participants