Skip to content

Failed to compile lambda_http example code #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Observer42 opened this issue Mar 21, 2019 · 11 comments
Closed

Failed to compile lambda_http example code #97

Observer42 opened this issue Mar 21, 2019 · 11 comments

Comments

@Observer42
Copy link
Contributor

Observer42 commented Mar 21, 2019

I got below error when building the lambda_http example code

use lambda_http::{lambda, IntoResponse, Request, RequestExt};
use lambda_runtime::{Context, error::HandlerError};

fn main() {
    lambda!(hello)
}

fn hello(
    request: Request,
    _ctx: Context
) -> Result<impl IntoResponse, HandlerError> {
    Ok(format!(
        "hello {}",
        request
            .query_string_parameters()
            .get("name")
            .unwrap_or_else(|| "stranger")
    ))
}

according to issue #87 , I chose to fetch lambda_http crate from git address
the dependencies in Cargo.toml are:

lambda_runtime = "0.2"
lambda_http = {git = "https://github.com/awslabs/aws-lambda-rust-runtime"}

error message:

type mismatch in function arguments

expected signature of `fn(http::request::Request<lambda_http::body::Body>, lambda_runtime_core::context::Context) -> _`

note: required because of the requirements on the impl of `lambda_http::Handler<_>` for `fn(http::request::Request<lambda_http::body::Body>, lambda_runtime_core::context::Context) -> std::result::Result<impl lambda_http::response::IntoResponse, lambda_runtime_errors::HandlerError> {hello}`
note: required by `lambda_http::start`rustc(E0631)
<::lambda_http::lambda macros>(1, 27): expected signature of `fn(http::request::Request<lambda_http::body::Body>, lambda_runtime_core::context::Context) -> _`
main.rs(8, 1): found signature of `fn(http::request::Request<lambda_http::body::Body>, lambda_runtime_core::context::Context) -> _`

It will not receive such error If I change the lambda_http version to 0.1.0
But in a more practical project, serde::Deserialize (#87 ) will be introduced, so I cannot choose 0.1.0

Is there any workaround? or is there any example to return the http response via lambda_runtime crate only (I would prefer this way, because lambda macro in runtime crate allow custom Error type which implements Fail + LambdaErrorExt + Display (though still not convenient, i.e. #94 ), while lambda in http crate allow HandlerError only)? Thanks in advance

@softprops
Copy link
Contributor

@davidbarsky would this issue be resolved if the http lambda crate were published today as is independently of the other crates?

@Observer42
Copy link
Contributor Author

Observer42 commented Mar 22, 2019

update: seems lambda_http::start is the wrapper of lambda_runtime::start, and (http) Response / Request can be transformed to internal struct LambdaResponse / LambdaRequest.

Currently my workaround is to create a struct similar to LambdaResponse, and put them in Output position in trait lambda_runtime::Handler. Then I don't need to import lambda_http crate...

@davidbarsky
Copy link
Contributor

Sorry for the delay, I’m catching up now. @softprops—maybe?

@softprops
Copy link
Contributor

I can try some experiments and see

@bburnichon
Copy link

@davidbarsky would this issue be resolved if the http lambda crate were published today as is independently of the other crates?

I cloned repository locally, changed Cargo.toml from lambda-http as follows:

~/Github/awslabs/aws-lambda-rust-runtime/lambda-http (master *=)$ git diff

diff --git a/lambda-http/Cargo.toml b/lambda-http/Cargo.toml
index e8e6d52..c8b147d 100644
--- a/lambda-http/Cargo.toml
+++ b/lambda-http/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "lambda_http"
-version = "0.1.0"
+version = "0.2.0"
 authors = ["Doug Tangren"]
 edition = "2018"
 description = "Rust API Gateway proxy event interfaces for AWS Lambda"
@@ -20,7 +20,7 @@ http = "0.1"
 serde = "^1"
 serde_json = "^1"
 serde_derive = "^1"
-lambda_runtime = { path = "../lambda-runtime", version = "^0.2" }
+lambda_runtime = "0.2"
 tokio = "^0.1"
 base64 = "0.10"
 failure = "0.1"

And then changed my Cargo.toml to reference this version instead of the one in crates.io:

diff --git a/Cargo.toml b/Cargo.toml
index 402fef2..e31644e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,7 +24,7 @@ actix-web = { optional = true, version = "0.7" }
 env_logger = { optional = true, version = "0.6" }
 listenfd = { optional =  true, version = "0.3"}
 lambda_runtime = { optional = true, version = "0.2" }
-lambda_http = { optional = true, version = "0.1" }
+lambda_http = { optional = true, version = "0.2", path = "/home/bburnichon/Github/awslabs/aws-lambda-rust-runtime/lambda-http" }
 #lambda_http = { optional = true, git = "https://github.com/awslabs/aws-lambda-rust-runtime" }
 simple-error = { optional = true, version = "0.1.13" }

I can now compile the example without the error message that @Observer42 obtained.

So I would say that publishing crates independently would solve the issue.

@softprops
Copy link
Contributor

@bburnichon awesome work!

I still had the issue mentioned above when depending on the latest git version. I think @bburnichon's trick looks promising: a temporary forced declaration of dependence on the published form of lambda_runtime instead of the latest source.

@softprops
Copy link
Contributor

@davidbarsky thoughts on trying this to publishing lambda-http with a version dependency on lambda_runtime = "0.2"?

@softprops
Copy link
Contributor

that would have a nice side effect of on the next update they all versions end up lining up to 0.3 or whatever they might be

@softprops
Copy link
Contributor

@davidbarsky sending another ping :)

@davidbarsky
Copy link
Contributor

@softprops Sorry about the delay—normal work has been a bit much recently. I think that's a good idea—I'll try to get a release out later today.

@jkshtj
Copy link

jkshtj commented Jan 21, 2021

Issue seems to have been fixed in release (#103).

@jkshtj jkshtj closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants