AWS 机密管理器/分页令牌错误不再有效 (boto3/python)

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

当我尝试获取所有机密管理器列表时出现以下错误:

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

密码是:

    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'])

如果有人能帮助我,我会很高兴。

您需要使用所需参数更新该部分。

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')