You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change introduces:
- Skeptic (https://github.com/budziq/rust-skeptic) for testing the README.md
- Remove #[macro_use], allowing for macros to be imported without any special syntax.
- Introduce a minimum Rust version of 1.30 for examples.
Signed-off-by: David Barsky <[email protected]>
This package makes it easy to run AWS Lambda Functions written in Rust. This workspace includes multiple crates:
4
-
***`lambda-runtime-client`** is a client SDK for the Lambda runtime APIs
5
-
***`lambda-runtime`** is a library that makes it easy to write Lambda functions in rust as executables
3
+
This package makes it easy to run AWS Lambda Functions written in Rust. This workspace includes two crates:
4
+
5
+
***`lambda-runtime-client`** is a client SDK for the Lambda Runtime APIs. You probably don't need to use this crate directly!
6
+
***`lambda-runtime`** is a library that makes it easy to write Lambda functions in Rust.
6
7
7
8
## Example function
8
-
The code below creates a simple function that receives an event with a `firstName` property and returns a hello world message for the given first name.
9
9
10
-
```rust
11
-
#[macro_use]
10
+
The code below creates a simple function that receives an event with a `greeting` and `name` field and returns a `GreetingResponse` message for the given name and greeting. Notice: to run these examples, we require a minimum Rust version of 1.30.
11
+
12
+
```rust,no_run
12
13
extern crate lambda_runtime as lambda;
13
-
#[macro_use]
14
14
extern crate serde_derive;
15
-
#[macro_use]
16
15
extern crate log;
17
16
extern crate simple_logger;
18
17
19
-
uselambda::error::HandlerError;
20
-
18
+
use serde_derive::{Serialize, Deserialize};
19
+
use lambda::{lambda, Context, error::HandlerError};
The code above is the same as the [basic example](https://github.com/awslabs/aws-lambda-rust-runtime/tree/master/lambda-runtime/examples/basic.rs) in the `lambda-runtime` crate. To deploy the basic sample as a Lambda function, we first build it with `cargo`. Remember that AWS Lambda uses Amazon Linux so you need to target your executable for an `x86_64-linux` platform.
53
+
The code above is the same as the [basic example](https://github.com/awslabs/aws-lambda-rust-runtime/tree/master/lambda-runtime/examples/basic.rs) in the `lambda-runtime` crate. To deploy the basic sample as a Lambda function, we first build it with `cargo`. Since Lambda uses Amazon Linux, you'll need to target your executable for an `x86_64-linux` platform.
For a custom runtime, AWS Lambda looks for an executable called `boostrap` in the deployment package zip. Rename the generated `basic` executable to `bootstrap` and add it to a zip archive.
Now that we have a deployment package (`rust.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.
65
+
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!
Defines the `RuntimeClient` trait and provides its `HttpRuntimeClient` implementation. The client fetches events and returns output as `Vec<u8>`.
88
89
89
90
For error reporting to the runtime APIs the library defines the `RuntimeApiError` trait and the `ErrorResponse` object. Custom errors for the APIs should implement the `to_response() -> ErrorResponse` method of the `RuntimeApiError` trait.
90
91
91
92
## lambda-runtime
93
+
92
94
This library makes it easy to create Rust executables for AWS lambda. The library defines a `lambda!()` macro. Call the `lambda!()` macro from your main method with a function that matches the `Handler` type:
93
-
```rust
95
+
96
+
```rust,ignore
94
97
pub type Handler<E, O> = fn(E, Context) -> Result<O, error::HandlerError>;
95
98
```
96
99
97
100
Optionally, you can pass your own instance of Tokio runtime to the `lambda!()` macro. See our [`with_custom_runtime.rs` example](https://github.com/awslabs/aws-lambda-rust-runtime/tree/master/lambda-runtime/examples/with_custom_runtime.rs)
98
101
99
102
## Custom event objects
100
103
101
-
To serialize and de-serialize events and responses we use the [`serde_json`](https://crates.io/crates/serde_json) library. To receive custom events, simply annotate your structure with Serde's macros:
104
+
To serialize and deserialize events and responses, we suggest using the use the [`serde`](https://github.com/serde-rs/serde) library. To receive custom events, annotate your structure with Serde's macros:
0 commit comments