Skip to content
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
296 changes: 155 additions & 141 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"lambda",
"lambda-attributes",
"lambda-http"
]
14 changes: 0 additions & 14 deletions lambda-attributes/Cargo.toml

This file was deleted.

98 changes: 0 additions & 98 deletions lambda-attributes/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion lambda-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ maintenance = { status = "actively-developed" }
base64 = "0.12"
http = "0.2"
lambda = { path = "../lambda", version = "0.1" }
lambda-attributes = { path = "../lambda-attributes", version = "0.1" }
serde = "^1"
serde_derive = "^1"
serde_json = "^1"
Expand Down
23 changes: 0 additions & 23 deletions lambda-http/examples/hello-http-without-macros.rs

This file was deleted.

21 changes: 16 additions & 5 deletions lambda-http/examples/hello-http.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use lambda_http::{
lambda::{lambda, Context},
IntoResponse, Request,
handler,
lambda::{self, Context},
IntoResponse, Request, RequestExt, Response,
};

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

#[lambda(http)]
#[tokio::main]
async fn main(_: Request, _: Context) -> Result<impl IntoResponse, Error> {
Ok("👋 world")
async fn main() -> Result<(), Error> {
lambda::run(handler(func)).await?;
Ok(())
}

async fn func(event: Request, _: Context) -> Result<impl IntoResponse, Error> {
Ok(match event.query_string_parameters().get("first_name") {
Some(first_name) => format!("Hello, {}!", first_name).into_response(),
_ => Response::builder()
.status(400)
.body("Empty first name".into())
.expect("failed to render response"),
})
}
33 changes: 4 additions & 29 deletions lambda-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,10 @@
//!
//! ## Hello World
//!
//! `lambda_http` handlers adapt to the standard `lambda::Handler` interface using the [`handler`](fn.handler.html) function.
//!
//! 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`.
//! You can learn more about these types [here](trait.IntoResponse.html).
//!
//! Adding an `#[lambda(http)]` attribute to a `#[tokio::run]`-decorated `main` function will setup and run the Lambda function.
//!
//! Note: this comes at the expense of any onetime initialization your lambda task might find value in.
//! The full body of your `main` function will be executed on **every** invocation of your lambda task.
//!
//! ```rust,no_run
//! use lambda_http::{lambda::{lambda, Context}, Request, IntoResponse};
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[lambda(http)]
//! #[tokio::main]
//! async fn main(_: Request, _: Context) -> Result<impl IntoResponse, Error> {
//! Ok("👋 world!")
//! }
//! ```
//!
//! ## Hello World, Without Macros
//!
//! For cases where your lambda might benfit from one time function initializiation might
//! prefer a plain `main` function and invoke `lambda::run` explicitly in combination with the [`handler`](fn.handler.html) function.
//! Depending on the runtime cost of your dependency bootstrapping, this can reduce the overall latency of your functions execution path.
//! The following example is how you would structure your Lambda such that you have a `main` function where you explicitly invoke
//! `lambda::run` in combination with the [`handler`](fn.handler.html) function. This pattern allows you to utilize global initialization
//! 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
//! your function's execution path.
//!
//! ```rust,no_run
//! use lambda_http::{handler, lambda};
Expand All @@ -51,7 +28,6 @@
//! lambda::run(handler(|request, context| async { Ok("👋 world!") })).await?;
//! Ok(())
//! }
//!
//! ```
//!
//! ## Leveraging trigger provided data
Expand Down Expand Up @@ -92,7 +68,6 @@ extern crate maplit;
pub use http::{self, Response};
use lambda::Handler as LambdaHandler;
pub use lambda::{self, Context};
pub use lambda_attributes::lambda;

mod body;
pub mod ext;
Expand Down
4 changes: 1 addition & 3 deletions lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ edition = "2018"
license = "Apache-2.0"

[features]
default = ["simulated", "derive"]
default = ["simulated"]
simulated = []
derive = ["lambda-attributes"]

[dependencies]
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }
Expand All @@ -18,7 +17,6 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1.0.39"
bytes = "1.0"
http = "0.2"
lambda-attributes = { path = "../lambda-attributes", version = "0.1.0", optional = true}
async-stream = "0.3"
futures = "0.3"
tracing = "0.1.13"
Expand Down
17 changes: 0 additions & 17 deletions lambda/examples/hello-without-macro.rs

This file was deleted.

17 changes: 12 additions & 5 deletions lambda/examples/hello.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use lambda::{lambda, Context};
use serde_json::Value;
use lambda::{handler_fn, Context};
use serde_json::{json, Value};

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

#[lambda]
#[tokio::main]
async fn main(event: Value, _: Context) -> Result<Value, Error> {
Ok(event)
async fn main() -> Result<(), Error> {
let func = handler_fn(func);
lambda::run(func).await?;
Ok(())
}

async fn func(event: Value, _: Context) -> Result<Value, Error> {
let first_name = event["firstName"].as_str().unwrap_or("world");

Ok(json!({ "message": format!("Hello, {}!", first_name) }))
}
33 changes: 3 additions & 30 deletions lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,13 @@

//! The official Rust runtime for AWS Lambda.
//!
//! There are two mechanisms available for defining a Lambda function:
//! 1. The `#[lambda]` attribute, which generates the boilerplate to
//! to launch and run a Lambda function.
//! The mechanism available for defining a Lambda function is as follows:
//!
//! The `#[lambda]` attribute _must_ be placed on an asynchronous main function.
//! However, as asynchronous main functions are not legal valid Rust
//! this means that the main function must also be decorated using a
//! `#[tokio::main]` attribute macro. This is available from
//! the [tokio](https://github.com/tokio-rs/tokio) crate.
//!
//! 2. A type that conforms to the [`Handler`] trait. This type can then be passed
//! to the the `lambda::run` function, which launches and runs the Lambda runtime.
//!
//! An asynchronous function annotated with the `#[lambda]` attribute must
//! accept an argument of type `A` which implements [`serde::Deserialize`], a [`lambda::Context`] and
//! return a `Result<B, E>`, where `B` implements [`serde::Serializable`]. `E` is
//! any type that implements `Into<Box<dyn std::error::Error + Send + Sync + 'static>>`.
//!
//! ```no_run
//! use lambda::{lambda, Context};
//! use serde_json::Value;
//!
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
//!
//! #[lambda]
//! #[tokio::main]
//! async fn main(event: Value, _: Context) -> Result<Value, Error> {
//! Ok(event)
//! }
//! ```
//! Create a type that conforms to the [`Handler`] trait. This type can then be passed
//! to the the `lambda::run` function, which launches and runs the Lambda runtime.
pub use crate::types::Context;
use client::Client;
use futures::stream::{Stream, StreamExt};
pub use lambda_attributes::lambda;
use serde::{Deserialize, Serialize};
use std::{
convert::{TryFrom, TryInto},
Expand Down