Skip to content

impossible to combine streaming and non-streaming in same lambda #610

@jones-ks

Description

@jones-ks

Imagine you have a lambda that returns JSON:

{"result":"this is the result"}

only imagine the JSON is much more complicated, with sub-objects, and it takes a long time to generate.

Because it takes a long time to generate, you'd like to implement a mode where a certain header or payload indicates to stream status updates, according to some message scheme.

The LambdaFunctionURLStreamingResponse seems to offer it!

But alas, it has this gnarly code:

if r.prelude == nil {
    ...
}
if r.prelude.Len() > 0 {
    return r.prelude.Read()
}

Now, whether you want it or not, the lambda outputs this prelude. The prelude doesn't match your original output! And as it is JSON, it breaks message decoding and prevents sending a single, sane JSON message output.

And on the streaming side, it messes with your streaming output - the receiver always has to skip this prelude.

Foiled! it's not possible to both implement streaming, and let it fall back to a simple JSON response. Therefore It's not backwards compatible - there is no way to roll out the change and keep existing plain-json-only clients working.

Furthermore, your error codes will break. The lambda always returns status code 200! Even if you return an error from the handler with no LambdaFunctionURLStreamResponse!

Could we please remove this gnarly prelude??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions