- Newest
- Most votes
- Most comments
Why This Happens: The filterCriteria parameters used in the initial request (including the lastObservedAt filter) must remain the same in the following requests.
If you're passing nextToken along with the filter criteria, but the filter criteria change between paginated requests, AWS Inspector2 will throw this error.
Potential Issue in Your Code: In your code, the filter criteria in the list_findings call might not be consistently the same across paginated requests because the condition for the nextToken logic may be modifying the filterCriteria parameters unintentionally. For example, if filter_date changes between requests, it can cause a mismatch.
Suggested Fix: To resolve this, ensure that the filter parameters remain unchanged between pagination requests, including lastObservedAt. You should pass the same filter_date in each call to list_findings and not modify it between paginated calls.
Here’s how you can adjust the code:
def get_findings(client, next_token, filter_date): # Build the base filter criteria filter_criteria = { 'lastObservedAt': [{"startInclusive": filter_date}] }
# Include the nextToken only if it's present
if next_token:
response = client.list_findings(
filterCriteria=filter_criteria,
nextToken=next_token
)
else:
response = client.list_findings(
filterCriteria=filter_criteria
)
return response
regards, M Zubair https://zeonedge.com
Relevant content
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 17 days ago
thanks for your response but I checked the cloud trail logs and the parameters don't change between requests. the error is thrown sporadically. I have updated the code to what you have suggested and still get the same error occassionaly.
it seems to happen when it is larger volumes of data being returned and more pages to paginate