Skip to content

Commit ad0a1d2

Browse files
authored
Renaming the lambda crate back to lambda_runtime and cleaning up documentation (#296)
* Renaming the lambda crate back to lambda_runtime and cleaning up documentation * Fixing failing cargo test
1 parent ba69687 commit ad0a1d2

File tree

16 files changed

+38
-60
lines changed

16 files changed

+38
-60
lines changed

CHANGELOG.md

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
22
members = [
3-
"lambda",
4-
"lambda-http"
3+
"lambda-http",
4+
"lambda-runtime"
55
]

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
This package makes it easy to run AWS Lambda Functions written in Rust. This workspace includes multiple crates:
66

7-
- [![Docs](https://docs.rs/lambda/badge.svg)](https://docs.rs/lambda) **`lambda`** is a library that provides a Lambda runtime for applications written in Rust.
7+
- [![Docs](https://docs.rs/lambda_runtime/badge.svg)](https://docs.rs/lambda_runtime) **`lambda-runtime`** is a library that provides a Lambda runtime for applications written in Rust.
88
- [![Docs](https://docs.rs/lambda_http/badge.svg)](https://docs.rs/lambda_http) **`lambda-http`** is a library that makes it easy to write API Gateway proxy event focused Lambda functions in Rust.
99

1010
## Example function
1111

1212
The code below creates a simple function that receives an event with a `firstName` field and returns a message to the caller. Notice: this crate is tested against latest stable Rust.
1313

1414
```rust,no_run
15-
use lambda::{handler_fn, Context};
15+
use lambda_runtime::{handler_fn, Context};
1616
use serde_json::{json, Value};
1717
1818
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
1919
2020
#[tokio::main]
2121
async fn main() -> Result<(), Error> {
2222
let func = handler_fn(func);
23-
lambda::run(func).await?;
23+
lambda_runtime::run(func).await?;
2424
Ok(())
2525
}
2626
@@ -31,7 +31,7 @@ async fn func(event: Value, _: Context) -> Result<Value, Error> {
3131
}
3232
```
3333

34-
The code above is the same as the [basic example](https://github.com/awslabs/aws-lambda-rust-runtime/blob/master/lambda/examples/hello-without-macro.rs) in the `lambda` crate.
34+
The code above is the same as the [basic example](https://github.com/awslabs/aws-lambda-rust-runtime/blob/master/lambda/examples/hello-without-macro.rs) in the `lambda_runtime` crate.
3535

3636
### Deployment
3737

@@ -56,13 +56,13 @@ $ echo $'[target.x86_64-unknown-linux-musl]\nlinker = "x86_64-linux-musl-gcc"' >
5656

5757
Compile one of the examples as a _release_ with a specific _target_ for deployment to AWS:
5858
```bash
59-
$ cargo build -p lambda --example basic --release --target x86_64-unknown-linux-musl
59+
$ cargo build -p lambda_runtime --example basic --release --target x86_64-unknown-linux-musl
6060
```
6161

6262
For [a custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), AWS Lambda looks for an executable called `bootstrap` in the deployment package zip. Rename the generated `basic` executable to `bootstrap` and add it to a zip archive.
6363

6464
```bash
65-
$ cp ./target/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap
65+
$ cp ./target/x86_64-unknown-linux-musl/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap
6666
```
6767

6868
Now that we have a deployment package (`lambda.zip`), we can use the [AWS CLI](https://aws.amazon.com/cli/) to create a new Lambda function. Make sure to replace the execution role with an existing role in your account!
@@ -127,7 +127,7 @@ $ npx serverless invoke -f hello -d '{"foo":"bar"}'
127127

128128
Alternatively, you can build a Rust-based Lambda function in a [docker mirror of the AWS Lambda provided runtime with the Rust toolchain preinstalled](https://github.com/softprops/lambda-rust).
129129

130-
Running the following command will start a ephemeral docker container which will build your Rust application and produce a zip file containing its binary auto-renamed to `bootstrap` to meet the AWS Lambda's expectations for binaries under `target/lambda/release/{your-binary-name}.zip`, typically this is just the name of your crate if you are using the cargo default binary (i.e. `main.rs`)
130+
Running the following command will start a ephemeral docker container which will build your Rust application and produce a zip file containing its binary auto-renamed to `bootstrap` to meet the AWS Lambda's expectations for binaries under `target/lambda_runtime/release/{your-binary-name}.zip`, typically this is just the name of your crate if you are using the cargo default binary (i.e. `main.rs`)
131131

132132
```bash
133133
# build and package deploy-ready artifact
@@ -159,12 +159,12 @@ $ unzip -o \
159159

160160
## `lambda`
161161

162-
`lambda` is a library for authoring reliable and performant Rust-based AWS Lambda functions. At a high level, it provides a few major components:
162+
`lambda_runtime` is a library for authoring reliable and performant Rust-based AWS Lambda functions. At a high level, it provides a few major components:
163163

164164
- `Handler`, a trait that defines interactions between customer-authored code and this library.
165-
- `lambda::run`, function that runs an `Handler`.
165+
- `lambda_runtime::run`, function that runs an `Handler`.
166166

167-
The function `handler_fn` converts a rust function or closure to `Handler`, which can then be run by `lambda::run`.
167+
The function `handler_fn` converts a rust function or closure to `Handler`, which can then be run by `lambda_runtime::run`.
168168

169169
## AWS event objects
170170

lambda-http/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ travis-ci = { repository = "awslabs/aws-lambda-rust-runtime" }
1717
maintenance = { status = "actively-developed" }
1818

1919
[dependencies]
20-
base64 = "0.12"
20+
base64 = "0.13.0"
2121
http = "0.2"
22-
lambda = { path = "../lambda", version = "0.1" }
22+
lambda_runtime = { path = "../lambda-runtime", version = "0.1" }
2323
serde = { version = "^1", features = ["derive"] }
2424
serde_json = "^1"
25-
serde_urlencoded = "0.6"
25+
serde_urlencoded = "0.7.0"
2626

2727
[dev-dependencies]
2828
log = "^0.4"

lambda-http/examples/hello-http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use lambda_http::{
22
handler,
3-
lambda::{self, Context},
3+
lambda_runtime::{self, Context},
44
IntoResponse, Request, RequestExt, Response,
55
};
66

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

99
#[tokio::main]
1010
async fn main() -> Result<(), Error> {
11-
lambda::run(handler(func)).await?;
11+
lambda_runtime::run(handler(func)).await?;
1212
Ok(())
1313
}
1414

lambda-http/src/ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Error for PayloadError {
6666
/// as well as `{"x":1, "y":2}` respectively.
6767
///
6868
/// ```rust,no_run
69-
/// use lambda_http::{handler, lambda::{self, Context}, Body, IntoResponse, Request, Response, RequestExt};
69+
/// use lambda_http::{handler, lambda_runtime::{self, Context}, Body, IntoResponse, Request, Response, RequestExt};
7070
/// use serde::Deserialize;
7171
///
7272
/// type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -81,7 +81,7 @@ impl Error for PayloadError {
8181
///
8282
/// #[tokio::main]
8383
/// async fn main() -> Result<(), Error> {
84-
/// lambda::run(handler(add)).await?;
84+
/// lambda_runtime::run(handler(add)).await?;
8585
/// Ok(())
8686
/// }
8787
///

lambda-http/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
//! ## Hello World
1313
//!
1414
//! 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
15+
//! `lambda_runtime::run` in combination with the [`handler`](fn.handler.html) function. This pattern allows you to utilize global initialization
1616
//! 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
1717
//! your function's execution path.
1818
//!
1919
//! ```rust,no_run
20-
//! use lambda_http::{handler, lambda};
20+
//! use lambda_http::{handler, lambda_runtime};
2121
//!
2222
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2323
//!
2424
//! #[tokio::main]
2525
//! async fn main() -> Result<(), Error> {
2626
//! // initialize dependencies once here for the lifetime of your
2727
//! // lambda task
28-
//! lambda::run(handler(|request, context| async { Ok("👋 world!") })).await?;
28+
//! lambda_runtime::run(handler(|request, context| async { Ok("👋 world!") })).await?;
2929
//! Ok(())
3030
//! }
3131
//! ```
@@ -36,13 +36,13 @@
3636
//! with the [`RequestExt`](trait.RequestExt.html) trait.
3737
//!
3838
//! ```rust,no_run
39-
//! use lambda_http::{handler, lambda::{self, Context}, IntoResponse, Request, RequestExt};
39+
//! use lambda_http::{handler, lambda_runtime::{self, Context}, IntoResponse, Request, RequestExt};
4040
//!
4141
//! type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
4242
//!
4343
//! #[tokio::main]
4444
//! async fn main() -> Result<(), Error> {
45-
//! lambda::run(handler(hello)).await?;
45+
//! lambda_runtime::run(handler(hello)).await?;
4646
//! Ok(())
4747
//! }
4848
//!
@@ -66,8 +66,8 @@
6666
extern crate maplit;
6767

6868
pub use http::{self, Response};
69-
use lambda::Handler as LambdaHandler;
70-
pub use lambda::{self, Context};
69+
use lambda_runtime::Handler as LambdaHandler;
70+
pub use lambda_runtime::{self, Context};
7171

7272
mod body;
7373
pub mod ext;
@@ -93,7 +93,7 @@ pub type Request = http::Request<Body>;
9393

9494
/// Functions serving as ALB and API Gateway REST and HTTP API handlers must conform to this type.
9595
///
96-
/// This can be viewed as a `lambda::Handler` constrained to `http` crate `Request` and `Response` types
96+
/// This can be viewed as a `lambda_runtime::Handler` constrained to `http` crate `Request` and `Response` types
9797
pub trait Handler: Sized {
9898
/// The type of Error that this Handler will return
9999
type Error;
@@ -105,7 +105,7 @@ pub trait Handler: Sized {
105105
fn call(&self, event: Request, context: Context) -> Self::Fut;
106106
}
107107

108-
/// Adapts a [`Handler`](trait.Handler.html) to the `lambda::run` interface
108+
/// Adapts a [`Handler`](trait.Handler.html) to the `lambda_runtime::run` interface
109109
pub fn handler<H: Handler>(handler: H) -> Adapter<H> {
110110
Adapter { handler }
111111
}
@@ -146,7 +146,7 @@ where
146146
}
147147
}
148148

149-
/// Exists only to satisfy the trait cover rule for `lambda::Handler` impl
149+
/// Exists only to satisfy the trait cover rule for `lambda_runtime::Handler` impl
150150
///
151151
/// User code should never need to interact with this type directly. Since `Adapter` implements `Handler`
152152
/// It serves as a opaque trait covering type.

lambda/Cargo.toml renamed to lambda-runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "lambda"
2+
name = "lambda_runtime"
33
version = "0.1.0"
44
authors = ["David Barsky <dbarsky@amazon.com>"]
55
description = "AWS Lambda Runtime"

lambda/examples/README.md renamed to lambda-runtime/examples/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ Runtime.ExitError
6363

6464
See _error-handling.rs_ example for more error handling options.
6565

66-
## macro.rs
67-
68-
The most basic example using `#[lambda]` macro to reduce the amount of boilerplate code.
69-
7066
**Deployment**:
7167
```bash
7268
cp ./target/x86_64-unknown-linux-musl/release/examples/macro ./bootstrap && zip lambda.zip bootstrap && rm bootstrap

lambda/examples/basic.rs renamed to lambda-runtime/examples/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This example requires the following input to succeed:
22
// { "command": "do something" }
33

4-
use lambda::{handler_fn, Context};
4+
use lambda_runtime::{handler_fn, Context};
55
use log::LevelFilter;
66
use serde::{Deserialize, Serialize};
77
use simple_logger::SimpleLogger;
@@ -35,7 +35,7 @@ async fn main() -> Result<(), Error> {
3535
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
3636

3737
let func = handler_fn(my_handler);
38-
lambda::run(func).await?;
38+
lambda_runtime::run(func).await?;
3939
Ok(())
4040
}
4141

0 commit comments

Comments
 (0)