I’m having an odd problem with querying AWS SecretsManager using the Python3 boto3 library. When I get a list of secrets I consistenty only get 10 when there’s more than that listed in the web console and it doesn’t include the ones I need. Sample code below.
import json
import boto3
import base64
session = boto3.session.Session('secretsmanager', 'eu-west-2')
client = boto3.client('secretsmanager')
secrets=client.list_secrets()
length=len(secrets['SecretList'])
print('Secrets found: '+str(length))
Has anyone else seen this issue?
Edit: after looking at the docs again it looks like it may be because I need to specify a NextToken parameter but I can’t find any examples of what this should look like.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.list_secrets
Edit2: it looks like I need to use pagination
Edit3: looks like you can’t paginate this call. Instead use NextToken parameter like:
secrets=client.list_secrets(MaxResults=10)
moreSecrets=client.list_secrets(MaxResults=10, NextToken=secrets['NextToken'])