awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.36k stars 343 forks source link

Extension registration fails with `Error("EOF while parsing a value", line: 1, column: 0)` #922

Closed bassmanitram closed 2 months ago

bassmanitram commented 2 months ago

I have the simplest possible generic extension designed to be run from a script so the script doesn't need to mess with the whole registration protocol via curl etc.

My original script (which does mess with curl) works well with the cargo lambda watch --only-lambda-apis -a 127.0.0.1 -p 2807 test runtime server.

Running this program, however, appears to get just about all the way through registration but then terminates with Error("EOF while parsing a value", line: 1, column: 0) - looks very JSON issue-y to me :).

The source is:

use std::env;
use lambda_extension::{service_fn, Error, Extension, LambdaEvent, NextEvent};
use tracing_subscriber::EnvFilter;

async fn handle(event: LambdaEvent) -> Result<(), Error> {
    match event.next {
        NextEvent::Shutdown(_e) => {
            // do nothing specific with the shutdown event
        }
        NextEvent::Invoke(_e) => {
            // do nothing specific with the invoke event - which we don't even register for
        }
    }
    Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())       
        .without_time()
        .with_ansi(false)
        .init();
    let mut args = env::args();
    args.next(); //lose the program name
    let extension_name = args.next().expect("First argument must be the extension name");
    Extension::new()
        .with_extension_name(&extension_name)
        .with_events_processor(service_fn(handle))
        .with_events(&["SHUTDOWN"])
        .register().await
        .expect("registration failed")
        .run().await
}

Note that I am building this with cargo build not cargo lambda build --extension because I'm building the Extension.

The intended use is something like this as the actual extensions script (that's simplistic, of course, but you get the idea I hope);

real-functionality.sh &
PID=$!
the-above-program my-extension-name
kill $PID
wait $PID

This works in the real Lambda service.

Trace logs:

bassmanitram commented 2 months ago

Capturing the request response flow...

REQUEST: Request { method: POST, uri: /.rt/2020-01-01/extension/register, version: HTTP/1.1, headers: {"user-agent": "aws-lambda-rust/0.11.1", "lambda-extension-name": "test-extension", "lambda-extension-accept-feature": "accountId", "content-type": "application/json", "host": "127.0.0.1:2807", "content-length": "23"}, body: Body(Streaming) }
RESPONSE: Response { status: 200, version: HTTP/1.1, headers: {"lambda-extension-identifier": "7cc1236c-b570-4cb8-bab1-924e7dbf0cd6", "content-length": "0", "date": "Thu, 05 Sep 2024 13:46:32 GMT"}, body: Body(Empty) }

Looks like the client is trying to parse JSON from an empty body, though I can't make it work even if I hack the response to 204 or replace the response body with valid JSON.

calavera commented 2 months ago

This is a bug in Cargo Lambda. https://github.com/cargo-lambda/cargo-lambda/pull/690 fixes the problem.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one.

bassmanitram commented 2 months ago

Perfect - Thx