You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm slightly confused about how to invoke the HTTP examples on the command line via cargo lambda invoke.
For example, the http-axum example provides a few HTTP accessible paths, but I'm unsure how to reach them. http-basic-lambda is even more frustrating, because it doesn't accept any arguments, yet the invoke sub-command requires that users specific data to sent.
What data should I be providing? How do I send GET vs POST requests? Is it possible to simply use curl?
Two follow-on questions. How is <lambda-function-name> defined? I assume that it's the name of the bin target.
Is it possible to elaborate on what data should I be providing to the functions. How does the JSON payload map to something that the function handler can interpret?
if you use the */lambda-url/<lambda-function-name>/* style then you can just curl as you would expect. cargo lambda is going to do the translation of your curl request into the JSON payload, and then the Rust Runtime is going to do the de-translation of that JSON payload back into an HTTP request.
curl -X GET -H "Content-Type: application/json" http://localhost:9001/lambda-url/http-warp/foo/bar
Hey Tim! I was in the exact predicament as you a few weeks back.
Two follow-on questions. How is defined? I assume that it's the name of the bin target.
Yes, lambda-function-name is the name of the package defined in Cargo.toml. You can get the specifics from the cargo-lambda invoke docs.
Is it possible to elaborate on what data should I be providing to the functions. How does the JSON payload map to something that the function handler can interpret?
If you are using the payload() method, you can view the implementation here. To elaborate further, if you expect the body of your request event to be of the following.
#[derive(Deserialize)]structRequestEvent{words:Vec<String>,number:i32}asyncfnhandler(event:Request) -> Result<Response<Body>,Error>{let payload = match event.payload::<RequestEvent>(){Ok(Some(payload)) => payload,Ok(None) => {returnOk(Response::builder().status(400).body("No body found".into()).map_err(Box::new)?)}Err(err) => {returnOk(Response::builder().status(400).body(format!("Error parsing body: {}", err).into()).map_err(Box::new)?)}};}
Ideally, the entire docs should be completely rewritten. To prevent further confusion, anything related to cargo-lambda should not be mentioned anywhere else apart from its dedicated section, but this is what we have to work with for now :)
Activity
[-]How should I invoke examples with multiple HTTP routes?[/-][+]How should I invoke HTTP examples locally?[/+]bnusunny commentedon Mar 2, 2023
Yes, you can use
curl. It is in the README now. https://github.com/awslabs/aws-lambda-rust-runtime#cargo-lambdatimClicks commentedon Mar 2, 2023
Thanks for your answer @bnusunny.
Two follow-on questions. How is
<lambda-function-name>defined? I assume that it's the name of thebintarget.Is it possible to elaborate on what data should I be providing to the functions. How does the JSON payload map to something that the function handler can interpret?
greenwoodcm commentedon Mar 2, 2023
if you use the
*/lambda-url/<lambda-function-name>/*style then you can just curl as you would expect.cargo lambdais going to do the translation of your curl request into the JSON payload, and then the Rust Runtime is going to do the de-translation of that JSON payload back into an HTTP request.winstxnhdw commentedon Mar 3, 2023
Hey Tim! I was in the exact predicament as you a few weeks back.
Yes,
lambda-function-nameis the name of the package defined inCargo.toml. You can get the specifics from the cargo-lambda invoke docs.If you are using the
payload()method, you can view the implementation here. To elaborate further, if you expect the body of your request event to be of the following.You should define a struct like so.
Ideally, the entire docs should be completely rewritten. To prevent further confusion, anything related to
cargo-lambdashould not be mentioned anywhere else apart from its dedicated section, but this is what we have to work with for now :)