Skip to content

Commit 5ae037e

Browse files
authored
Remove lambda attributes (#282)
1 parent 721f616 commit 5ae037e

File tree

12 files changed

+191
-367
lines changed

12 files changed

+191
-367
lines changed

Cargo.lock

Lines changed: 155 additions & 141 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[workspace]
22
members = [
33
"lambda",
4-
"lambda-attributes",
54
"lambda-http"
65
]

lambda-attributes/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

lambda-attributes/src/lib.rs

Lines changed: 0 additions & 98 deletions
This file was deleted.

lambda-http/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ maintenance = { status = "actively-developed" }
1919
base64 = "0.12"
2020
http = "0.2"
2121
lambda = { path = "../lambda", version = "0.1" }
22-
lambda-attributes = { path = "../lambda-attributes", version = "0.1" }
2322
serde = "^1"
2423
serde_derive = "^1"
2524
serde_json = "^1"

lambda-http/examples/hello-http-without-macros.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

lambda-http/examples/hello-http.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
use lambda_http::{
2-
lambda::{lambda, Context},
3-
IntoResponse, Request,
2+
handler,
3+
lambda::{self, Context},
4+
IntoResponse, Request, RequestExt, Response,
45
};
56

67
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
78

8-
#[lambda(http)]
99
#[tokio::main]
10-
async fn main(_: Request, _: Context) -> Result<impl IntoResponse, Error> {
11-
Ok("👋 world")
10+
async fn main() -> Result<(), Error> {
11+
lambda::run(handler(func)).await?;
12+
Ok(())
13+
}
14+
15+
async fn func(event: Request, _: Context) -> Result<impl IntoResponse, Error> {
16+
Ok(match event.query_string_parameters().get("first_name") {
17+
Some(first_name) => format!("Hello, {}!", first_name).into_response(),
18+
_ => Response::builder()
19+
.status(400)
20+
.body("Empty first name".into())
21+
.expect("failed to render response"),
22+
})
1223
}

lambda-http/src/lib.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,10 @@
1111
//!
1212
//! ## Hello World
1313
//!
14-
//! `lambda_http` handlers adapt to the standard `lambda::Handler` interface using the [`handler`](fn.handler.html) function.
15-
//!
16-
//! The simplest case of an http handler is a function of an `http::Request` to a type that can be lifted into an `http::Response`.
17-
//! You can learn more about these types [here](trait.IntoResponse.html).
18-
//!
19-
//! Adding an `#[lambda(http)]` attribute to a `#[tokio::run]`-decorated `main` function will setup and run the Lambda function.
20-
//!
21-
//! Note: this comes at the expense of any onetime initialization your lambda task might find value in.
22-
//! The full body of your `main` function will be executed on **every** invocation of your lambda task.
23-
//!
24-
//! ```rust,no_run
25-
//! use lambda_http::{lambda::{lambda, Context}, Request, IntoResponse};
26-
//!
27-
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
28-
//!
29-
//! #[lambda(http)]
30-
//! #[tokio::main]
31-
//! async fn main(_: Request, _: Context) -> Result<impl IntoResponse, Error> {
32-
//! Ok("👋 world!")
33-
//! }
34-
//! ```
35-
//!
36-
//! ## Hello World, Without Macros
37-
//!
38-
//! For cases where your lambda might benfit from one time function initializiation might
39-
//! prefer a plain `main` function and invoke `lambda::run` explicitly in combination with the [`handler`](fn.handler.html) function.
40-
//! Depending on the runtime cost of your dependency bootstrapping, this can reduce the overall latency of your functions execution path.
14+
//! The following example is how you would structure your Lambda such that you have a `main` function where you explicitly invoke
15+
//! `lambda::run` in combination with the [`handler`](fn.handler.html) function. This pattern allows you to utilize global initialization
16+
//! of tools such as loggers, to use on warm invokes to the same Lambda function after the first request, helping to reduce the latency of
17+
//! your function's execution path.
4118
//!
4219
//! ```rust,no_run
4320
//! use lambda_http::{handler, lambda};
@@ -51,7 +28,6 @@
5128
//! lambda::run(handler(|request, context| async { Ok("👋 world!") })).await?;
5229
//! Ok(())
5330
//! }
54-
//!
5531
//! ```
5632
//!
5733
//! ## Leveraging trigger provided data
@@ -92,7 +68,6 @@ extern crate maplit;
9268
pub use http::{self, Response};
9369
use lambda::Handler as LambdaHandler;
9470
pub use lambda::{self, Context};
95-
pub use lambda_attributes::lambda;
9671

9772
mod body;
9873
pub mod ext;

lambda/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ edition = "2018"
77
license = "Apache-2.0"
88

99
[features]
10-
default = ["simulated", "derive"]
10+
default = ["simulated"]
1111
simulated = []
12-
derive = ["lambda-attributes"]
1312

1413
[dependencies]
1514
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }
@@ -18,7 +17,6 @@ serde = { version = "1", features = ["derive"] }
1817
serde_json = "1.0.39"
1918
bytes = "1.0"
2019
http = "0.2"
21-
lambda-attributes = { path = "../lambda-attributes", version = "0.1.0", optional = true}
2220
async-stream = "0.3"
2321
futures = "0.3"
2422
tracing = "0.1.13"

lambda/examples/hello-without-macro.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)