Dependencies

First, we need to create a new minimal-lambda crate and add the following dependencies to it:

[dependencies]
lambda_runtime = { git = "https://github.com/awslabs/aws-lambda-rust-runtime" }
log = "0.4"
rand = "0.5"
serde = "1.0"
serde_derive = "1.0"
simple_logger = "1.0"

The main dependency we need is lambda_runtime, which is an official crate for writing lambda functions for AWS Lambda platform using Rust. We used a version from GitHub because, at the time of writing, this crate was in active development.

AWS prints the output of all the lambda functions as logs, and we will use the simple_logger crate, which prints all logs to stdout.

We also need to override the name of a binary with lambda, because an environment that run, AWS Lambda expects to find a binary called bootstrap that implements the lambda function. Let's rename the binary produced by our example:

[[bin]]
name = "bootstrap"
path = "src/main.rs"

That's enough to start writing a minimal microservice for a serverless environment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.163.229