Skip to content

Move to netlify_lambda_http crate #3

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

Merged
merged 6 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
[package]
name = "warp_lambda"
description = "A super simple crate to let you use [warp filters](https://github.com/seanmonstar/warp) with [aws lambda runtime](https://github.com/awslabs/aws-lambda-rust-runtime)"
license = "MIT"
readme = "README.md"
repository = "https://github.com/aslamplr/warp_lambda"
homepage = "https://github.com/aslamplr/warp_lambda#warp_lambda"
version = "0.1.0"
authors = ["Aslam Ahammed <[email protected]>"]
edition = "2018"
keywords = ["lambda", "aws-lambda", "warp", "serverless", "warp-lambda"]
categories = ["web-programming", "web-programming::http-server"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[badges]
maintenance = { status = "experimental" }

[dependencies]
lambda_http = { git = "https://github.com/awslabs/aws-lambda-rust-runtime.git", rev = "c36409c5e65f994c7ff48510cd111905b4aa77c9" }
warp = "0.2.5"
tower = "0.3.1"
thiserror = "1.0.21"
aws_lambda_events = "0.4"
# Reference issue https://github.com/awslabs/aws-lambda-rust-runtime/issues/274
# for the reason to move away from official awslabs/aws-lambda-rust-runtime
# in favor of using netlify's fork lamedh-dev/aws-lambda-rust-runtime
netlify_lambda_http = "0.2"
warp = "0.3"
tower = "0.4"
thiserror = "1.0"

[dev-dependencies]
anyhow = "1.0.33"
tokio = { version = "0.2", features = [ "full" ]}
anyhow = "1.0"
tokio = { version = "1.2", features = [ "full" ]}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

A super simple crate to let you use [warp filters](https://github.com/seanmonstar/warp) with [aws lambda runtime](https://github.com/awslabs/aws-lambda-rust-runtime)

> Note: Using fork of [awslabs/aws-lambda-rust-runtime](https://github.com/awslabs/aws-lambda-rust-runtime) by Netlify devs [lamedh-dev/aws-lambda-rust-runtime](https://github.com/lamedh-dev/aws-lambda-rust-runtime)
> Due to issue [#216](https://github.com/awslabs/aws-lambda-rust-runtime/issues/216) and an alternative from Netlify devs [#274](https://github.com/awslabs/aws-lambda-rust-runtime/issues/274)

> `Warning: This is experimental and not production ready! uses non stable version of aws_lambda_rust_runtime`

# Example

Add `warp_lambda`, `warp` and `tokio` to your dependencies:

> Note: Planning to publish `warp_lambda` crate to crates.io soon once the latest changes to aws-lambda-rust-runtime is released. Then the git dependencies won't be necessary.

```toml
tokio = { version = "0.2", features = [ "full" ]}
warp = "0.2"
warp_lambda = { git = "https://github.com/aslamplr/warp_lambda.git", rev = "4eab5db86da49dcca1f5515a8173765acfcaee0a" }
tokio = { version = "1.2.0", features = [ "full" ]}
warp = "0.3"
warp_lambda = "0.1"
```

And then get started in your `main.rs`:
Expand Down
2 changes: 1 addition & 1 deletion examples/lambda_request_context/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn main() -> Result<()> {
// Request context when invoked from an ALB event
RequestContext::Alb(alb) => format!("::ALB:: {:?}", alb),
// Request context when invoked from an API Gateway REST event
RequestContext::ApiGateway(api_gw) => format!("::API_GW:: {:?}", api_gw),
RequestContext::ApiGatewayV1(api_gw) => format!("::API_GW:: {:?}", api_gw),
// Request context when invoked from an API Gateway HTTP event
RequestContext::ApiGatewayV2(api_gw2) => format!("::API_GW(V2):: {:?}", api_gw2),
};
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use core::future::Future;
use std::convert::Infallible;
use std::pin::Pin;

pub use lambda_http;
pub use netlify_lambda_http as lambda_http;
pub use warp;

use lambda_http::{
use aws_lambda_events::encodings::Body as LambdaBody;
use netlify_lambda_http::{
handler,
lambda::{self, Context},
Body as LambdaBody, Handler, Request, Response,
Handler, Request, Response,
};
use warp::hyper::Body as WarpBody;

Expand Down Expand Up @@ -45,7 +46,7 @@ impl<F> Handler for WarpHandler<F>
where
F: tower::Service<WarpRequest, Response = WarpResponse, Error = Infallible> + 'static,
{
type Response = Response<lambda_http::Body>;
type Response = Response<LambdaBody>;
type Error = Error;
type Fut = WarpHandlerFuture<Self::Response, Self::Error>;

Expand Down