def handler()

in detection-ml-wksp/aws_lambda/guardduty_ingest.py [0:0]


def handler(event, context):
    # Load environment variables for input and output locations
    findings_input_bucket = os.environ['INPUT_BUCKET']
    findings_input_prefix = os.environ['INPUT_PREFIX']
    tuples_output_bucket = os.environ['OUTPUT_BUCKET']
    tuples_output_key = os.environ['OUTPUT_KEY']

    # Create a Boto3 session and S3 client
    session = boto3.session.Session()
    s3_client = session.client('s3')

    tuples = []

    # Load the GuardDuty findings for the workshop
    findings = load_workshop_findings(s3_client, findings_input_bucket, findings_input_prefix)
    
    # Process the GuardDuty findings
    for finding in findings:
        # TODO - Change to print_short_finding(finding)
        print_full_finding(finding)
        
        # TODO - Uncomment next line to get tuples for each finding
        # tuples.extend(get_tuples(finding))

    # Write the tuples to S3 where they can be read by the Sagemaker algorithm
    if len(tuples) > 0:
        logger.info('Writing tuples to s3://%s/%s', tuples_output_bucket, tuples_output_key)

        s3_client.put_object(
            Bucket=tuples_output_bucket,
            Key=tuples_output_key,
            ContentType='text/csv',
            Body='\n'.join(tuples),
        )