<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _deliver_errored_events(errstream, recs):
 """Deliver errors to error stream."""

    rlogger.info("Going to handle %s failed events", len(recs))
    rlogger.info(
        "First failed event: %s", json.dumps(recs[0], indent=4))

    kinesis_stream = errstream.get("kinesis_stream")
    randomkey = str(uuid.uuid4())
    if kinesis_stream:
        send_to_kinesis_stream(
            recs,
            kinesis_stream,
            partition_key=errstream.get("partition_key", randomkey))
        rlogger.info("Sent errors to Kinesis stream '%s'", errstream)

    delivery_stream = errstream.get("firehose_delivery_stream")
    if delivery_stream:
        send_to_delivery_stream(errevents, delivery_stream)
        rlogger.info("Sent error payload to Firehose delivery stream '%s'",
                     delivery_stream)