Skip to main content

Module eventstream

Module eventstream 

Source
Expand description

Minimal application/vnd.amazon.eventstream frame encoder.

This is the wire format AWS uses for streaming responses on InvokeWithResponseStream, S3 SelectObjectContent, Kinesis SubscribeToShard, Transcribe, etc. Each frame is:

+-----------------------------------+
| total length        (u32 BE)      |
| headers length      (u32 BE)      |
| prelude CRC32       (u32 BE)      |  CRC of the two preceding u32s
| headers bytes       (raw)         |
| payload bytes       (raw)         |
| message CRC32       (u32 BE)      |  CRC of the whole frame so far
+-----------------------------------+

Each header is encoded as:

+---------------------------------------+
| name length     (u8)                  |
| name bytes                            |
| value type      (u8)                  |  7 = string
| value length    (u16 BE) [for strings]|
| value bytes                           |
+---------------------------------------+

Only the string header type (7) is needed for Lambda’s response stream — :event-type, :content-type, :message-type are all short ASCII strings. Other value types (bool, int, byte_array, timestamp, uuid) aren’t required here and are intentionally omitted to keep the surface minimal.

Functions§

encode_frame
Encode a single eventstream frame from a list of (name, value) string headers and a payload byte slice. Returns the bytes ready to be written to the response body.
invoke_complete_frame
Build the terminal InvokeComplete event frame. error_code / error_details are None on success; log_result_b64 is the base64-encoded last 4 KiB of the function’s tail log (empty string when no log was captured).
payload_chunk_frame
Build a PayloadChunk event frame carrying a slice of the function’s streamed response. AWS sends one of these per logical chunk emitted by the function (e.g. each responseStream.write(...) call in a Node.js streaming handler). The body is the raw chunk bytes — AWS does not wrap them in JSON; clients reconstruct the response by concatenating the payloads of every PayloadChunk event.