简体   繁体   中英

AWS secrets manager / Got error of pagination token is no longer valid (boto3/python)

I am getting the following error when I try to get all secrets manager list:

botocore.errorfactory.InvalidNextTokenException: An error occurred (InvalidNextTokenException) when calling the ListSecrets operation: The pagination token is no longer valid.

the code is:

    aws_access_key_id="VALID_ACCESS_KEY",
    aws_secret_access_key="VALID_SECRETS_ACCESS",
    region_name="eu-west-1"
    )
    client = session.client('secretsmanager')

    response = client.list_secrets(
        MaxResults=100,
        NextToken='string',
        Filters=[
            {
                'Key': 'name',
                'Values': [
                'string',
                ]
            },
        ],
        SortOrder='desc')
    page_iterator = client.paginate(key='name', PaginationConfig={'MaxItems': 100,'PageSize':100,'StartingToken':'string'})    
    for page in page_iterator:
        contents = page['Contents']
        print ('Received number of results: ', len(contents))
        for obj in contents:
            print (obj['Key'])

I will be happy if anyone can help me.

You need to update the section with your required parameters.

response = client.list_secrets(
          MaxResults=100,
          NextToken='string',  #can be removed if you're secrets are not more than the max result otherwise you needed a while loop 
          Filters=[
              {
                  'Key': 'name', # update with your filter details 
                   'Values': [
                  'string',
                  ]
              },
          ],
          SortOrder='desc')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM