Closed
Description
Hello,
APIGW has the following types:
- HTTP
- REST
- WebSocket
It seems to me that the lambda_http::Request works only for APIGW HTTP API and not for the rest of the types.
I am currently trying the REST API
your sample code:
use lambda_http::{handler, lambda_runtime::{self, Context, Error}, IntoResponse, Request, RequestExt};
#[tokio::main]
async fn main() -> Result<(), Error> {
lambda_runtime::run(handler(|event: Request, ctx: Context| {
execute(event, ctx)
}))
.await?;
Ok(())
}
pub async fn execute(request: Request, _ctx: Context) -> Result<impl IntoResponse, Error> {
println!("{:?}", request);
Ok(format!(
"hello {}",
request
.query_string_parameters()
.get("name")
.unwrap_or_else(|| "stranger")
))
}
error:
thread 'main' panicked at 'failed to build request: http::Error(InvalidUri(InvalidFormat))',
if you try to use for example
use aws_lambda_events::event::apigw::ApiGatewayProxyRequest;
you will have this:
type mismatch in closure arguments
required because of the requirements on the impl of `lambda_http::Handler<'_>`
found signature of `fn(ApiGatewayProxyRequest, lambda_http::Context) -> _`
expected signature of `fn(Request<lambda_http::Body>, lambda_http::Context) ->
note: required because of the requirements on the impl of `lambda_http::Handler<'_>` for `[closure@services/session-manager/src/bin/device.rs:6:33: 8:6]`
note: required by a bound in `Adapter`
using the normal lambda_runtime like this
Ok(json!({
"statusCode": 200,
"headers": {
"Content-Type": "application/json",
},
"body": {
"message": "ciao"
}
}))
you will get:
Received response. Status: 200
Endpoint response body before transformations: {"body":{"message":"ciao"},"headers":{"Content-Type":"application/json"},"statusCode":201}
Execution failed due to configuration error: Malformed Lambda proxy response.
Method completed with status: 502
Thanks,
Dan
Metadata
Metadata
Assignees
Labels
No labels