I have a scenario where I have one lambda which calls another lambda.
To emulate this locally, I have a debug assertion that invoke instead of invoking the lambda on AWS:
pub async fn invoke_deferred_task(payload: DeferredTaskPayload) {
let payload = serde_json::to_string(&payload).unwrap();
// Invoke a lambda to finish the work
#[cfg(debug_assertions)]
{
let root_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
#[expect(clippy::zombie_processes)]
std::process::Command::new("cargo")
.args([
"lambda",
"invoke",
"deferred_lambda",
"--data-ascii",
&payload,
])
.current_dir(root_dir)
.spawn()
.expect("Failed to invoke lambda in debug mode");
}
#[cfg(not(debug_assertions))]
{
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
let lambda_client = aws_sdk_lambda::Client::new(&config);
let deferred_lambda_name =
std::env::var("DEFERRED_LAMBDA_NAME").expect("missing DEFERRED_LAMBDA_NAME");
lambda_client
.invoke()
.invocation_type(aws_sdk_lambda::types::InvocationType::Event)
.function_name(deferred_lambda_name)
.payload(aws_sdk_lambda::primitives::Blob::new(payload))
.send()
.await
.expect("Failed to invoke lambda in production mode");
}
}
This works quite well, but when I add --bin <..> to my cargo lambda watch, trying to invoke it locally gives me an error:
INFO starting lambda function function="haloai_deferred_lambda" manifest=Some("Cargo.toml") cmd=Exec { prog: "/Users/simbleau/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo", args: ["run", "--color", "auto", "--manifest-path", "Cargo.toml", "--bin", "mylambda", "--bin", "deferred_lambda"] }
error: `cargo run` can run at most one executable, but multiple were specified
help: available targets:
bin `haloai_deferred_lambda` in package `haloai`
bin `haloai_lambda` in package `haloai`
Im not sure why, but it seems to add the watched bin to the args, so we get two --bins:
"--bin", "mylambda", "--bin", "deferred_lambda"
I have a scenario where I have one lambda which calls another lambda.
To emulate this locally, I have a debug assertion that invoke instead of invoking the lambda on AWS:
This works quite well, but when I add
--bin <..>to mycargo lambda watch, trying to invoke it locally gives me an error:Im not sure why, but it seems to add the watched bin to the args, so we get two --bins:
"--bin", "mylambda", "--bin", "deferred_lambda"