-
Notifications
You must be signed in to change notification settings - Fork 363
Description
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: