Skip to content

Commit f607efa

Browse files
committed
Add README files for the new crates.
Signed-off-by: David Calavera <[email protected]>
1 parent 6110926 commit f607efa

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This package makes it easy to run AWS Lambda Functions written in Rust. This wor
66

77
- [![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.
9+
- [![Docs](https://docs.rs/lambda_extension/badge.svg)](https://docs.rs/lambda_extension) **`lambda-extension`** is a library that makes it easy to write Lambda Runtime Extensions in Rust.
10+
- [![Docs](https://docs.rs/lambda_runtime_api_client/badge.svg)](https://docs.rs/lambda_runtime_api_client) **`lambda-runtime-api-client`** is a shared library between the lambda runtime and lambda extension libraries that includes a common API client to talk with the AWS Lambda Runtime API.
11+
912

1013
## Example function
1114

lambda-extension/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "Apache-2.0"
88
repository = "https://github.com/awslabs/aws-lambda-rust-runtime"
99
categories = ["web-programming::http-server"]
1010
keywords = ["AWS", "Lambda", "API"]
11-
readme = "../README.md"
11+
readme = "README.md"
1212

1313
[dependencies]
1414
tokio = { version = "1.0", features = ["macros", "io-util", "sync", "rt-multi-thread"] }

lambda-extension/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Runtime Extensions for AWS Lambda in Rust
2+
3+
[![Docs](https://docs.rs/lambda_extension/badge.svg)](https://docs.rs/lambda_extension)
4+
5+
**`lambda-extension`** is a library that makes it easy to write AWS Lambda Runtime Extensions in Rust.
6+
7+
## Example extension
8+
9+
The code below creates a simple extension that's registered to every `INVOKE` and `SHUTDOWN` events, and logs them in CloudWatch.
10+
11+
```rust,no_run
12+
use lambda_extension::{extension_fn, Error, NextEvent};
13+
use log::LevelFilter;
14+
use simple_logger::SimpleLogger;
15+
use tracing::info;
16+
17+
async fn log_extension(event: NextEvent) -> Result<(), Error> {
18+
match event {
19+
NextEvent::Shutdown(event) => {
20+
info!("{}", event);
21+
}
22+
NextEvent::Invoke(event) => {
23+
info!("{}", event);
24+
}
25+
}
26+
Ok(())
27+
}
28+
29+
#[tokio::main]
30+
async fn main() -> Result<(), Error> {
31+
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
32+
33+
let func = extension_fn(log_extension);
34+
lambda_extension::run(func).await
35+
}
36+
```
37+
38+
## Deployment
39+
40+
Lambda extensions can be added to your functions either using [Lambda layers](https://docs.aws.amazon.com/lambda/latest/dg/using-extensions.html#using-extensions-config), or adding them to [containers images](https://docs.aws.amazon.com/lambda/latest/dg/using-extensions.html#invocation-extensions-images). Regardless of how you deploy them, the extensions MUST be compiled against the same architecture that your lambda functions runs on. The only two architectures that AWS Lambda supports are `aarch64-unknown-linux-gnu` for ARM functions, and `x86_64-unknown-linux-gnu` for x86 functions.
41+
42+
### Building extensions
43+
44+
Once you've decided which target you'll use, you can install it by running the next `rustup` command:
45+
46+
```bash
47+
$ rustup target add x86_64-unknown-linux-gnu
48+
```
49+
50+
Then, you can compile the extension against that target:
51+
52+
```bash
53+
$ cargo build -p lambda_extension --example basic --release --target x86_64-unknown-linux-gnu
54+
```
55+
56+
This previous command will generate a binary file in `target/x86_64-unknown-linux-gnu/release/examples` called `basic`. When the extension is registered with the [Runtime Extensions API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html#runtimes-extensions-api-reg), that's the name that the extension will be registered with. If you want to register the extension with a different name, you only have to rename this binary file and deploy it with the new name.

lambda-runtime-api-client/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "Apache-2.0"
88
repository = "https://github.com/awslabs/aws-lambda-rust-runtime"
99
categories = ["web-programming::http-server"]
1010
keywords = ["AWS", "Lambda", "API"]
11-
readme = "../README.md"
11+
readme = "README.md"
1212

1313
[dependencies]
1414
http = "0.2"

lambda-runtime-api-client/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# AWS Lambda Runtime API Client
2+
3+
[![Docs](https://docs.rs/lambda_runtime_api_client/badge.svg)](https://docs.rs/lambda_runtime_api_client)
4+
5+
**`lambda-runtime-api-client`** is a library to interact with the AWS Lambda Runtime API.
6+
7+
This crate provides simple building blocks to send REST request to this API.
8+
9+
## Example
10+
11+
```rust,no_run
12+
use http::{Method, Request};
13+
use hyper::Body;
14+
use lambda_runtime_api_client::{build_request, Client, Error};
15+
16+
fn register_request(extension_name: &str, events: &[&str]) -> Result<Request<Body>, Error> {
17+
let events = serde_json::json!({ "events": events });
18+
19+
let req = build_request()
20+
.method(Method::POST)
21+
.uri("/2020-01-01/extension/register")
22+
.header("Lambda-Extension-Name", extension_name)
23+
.body(Body::from(serde_json::to_string(&events)?))?;
24+
25+
Ok(req)
26+
}
27+
28+
#[tokio::main]
29+
async fn main() -> Result<(), Error> {
30+
let client = Client::builder().build()?;
31+
let request = register_request("my_extension", &["INVOKE"])?;
32+
33+
client.call(request).await
34+
}
35+
```

0 commit comments

Comments
 (0)