[Python] How to get millions of security hub findings using boto3

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    we are having 7millions of security hub findings and I'm trying to fetch these by using boto3 securityhub get_findings() method but as the findings are huge it is taking lot of time, I am looking for your suggestions.

    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, kindly suggest the best way to get all the 7m findings. Please note that I can't use any other filters other than ProductName as Inspector as I need all the securityhub findings of the inspector .

    Continue reading...

Compartilhe esta Página