from typing import Dict
import random


def chunk(event: Dict, _c: Dict) -> Dict:
    """
    Lambda function to process a chunk of the records.

    :param event: lambda expected event object
    :param _c: lambda expected context object (unused)
    :returns: results used for downstream processing and conditional checks
    """

    chunk_size = 5
    records_to_process = event.get('records', [])

    if len(records_to_process) < chunk_size:
        chunk = records_to_process
        records = []
    else:
        chunk = records_to_process[:chunk_size]
        records = records_to_process[chunk_size:]

    # fake processing with random response code
    print(f'This chunk was processed:\n{chunk}')
    response = random.choice([200, 429, 503])

    return {'chunkProcessed': chunk, 'chunkResponse': response, 'records': records, 'recordsRemaining': len(records)}