we have 7 million of security hub findings and I'm trying to fetch these by using boto3 securityhub get_findings()
method but as the number of findings is huge it is taking lot of time.
import boto3
securityhub_client=boto3.client('securityhub')
def get_all_findings(securityhub_client):
nexttoken=""
inspector_findings=[]
while True:
try:
if nexttoken:
findings=securityhub_client.get_findings(
NextToken=nexttoken,
maxResults=100,
Filters={
'ProductName':[
{
'value':'Inspector',
'Comparison':'EQUALS'
},
],
}
)
inspector_findings.extend(findings['Findings'])
nexttoken=findings.get('NextToken')
if not nexttoken:
break
except Exception as e:
print('Some issue occurred',e)
break
return inspector_findings
all_findings=get_all_findings(securityhub_client)
print("all findings",all_findings)
here the code is executing successfully but it's taking a lot of time. what is the best way to get all the 7m findings?
I can't use any other filters other than ProductName as Inspector as I need all the securityhub findings of the inspector.