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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/target
/.cargo
lambda-runtime/libtest.rmeta
lambda-runtime/libtest.rmeta

# Built AWS Lambda zipfile
lambda.zip

# output.json from example docs
output.json
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Rust Runtime for AWS Lambda

[![Build Status](https://travis-ci.org/awslabs/aws-lambda-rust-runtime.svg?branch=master)](https://travis-ci.org/awslabs/aws-lambda-rust-runtime)

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

- [![Docs](https://docs.rs/lambda_runtime_client/badge.svg)](https://docs.rs/lambda_runtime_client) **`lambda-runtime-client`** is a client SDK for the Lambda Runtime APIs. You probably don't need to use this crate directly!
Expand Down Expand Up @@ -62,21 +60,21 @@ There are currently multiple ways of building this package: manually, and the [S
To deploy the basic sample as a Lambda function using the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html), we first need to manually build it with [`cargo`](https://doc.rust-lang.org/cargo/). Since Lambda uses Amazon Linux, you'll need to target your executable for an `x86_64-linux` platform.

```bash
$ cargo build -p lambda_runtime --example basic --release
$ cargo build -p lambda --example hello --release
```

For a custom runtime, 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.

```bash
$ cp ./target/release/examples/basic ./bootstrap && zip lambda.zip bootstrap && rm bootstrap
$ cp ./target/release/examples/hello ./bootstrap && zip lambda.zip bootstrap && rm bootstrap
```

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!

```bash
$ aws lambda create-function --function-name rustTest \
--handler doesnt.matter \
--zip-file file://./lambda.zip \
--zip-file fileb://./lambda.zip \
--runtime provided \
--role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \
--environment Variables={RUST_BACKTRACE=1} \
Expand All @@ -92,6 +90,9 @@ $ aws lambda invoke --function-name rustTest \
$ cat output.json # Prints: {"message":"Hello, world!"}
```

**Note:** `--cli-binary-format raw-in-base64-out` is a required
argument when using the AWS CLI version 2. [More Information](https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam)

#### Serverless Framework

Alternatively, you can build a Rust-based Lambda function declaratively using the [Serverless framework Rust plugin](https://github.com/softprops/serverless-rust).
Expand Down
1 change: 1 addition & 0 deletions lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "lambda"
version = "0.1.0"
authors = ["David Barsky <[email protected]>"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might drop the "client" part of this. That's an implementation detail most users won't likely care or care to know about. Just calling this "AWS Lambda Rust runtime" might get the point across and be a little bit more inline with https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Copy link
Contributor Author

@darrenmeehan darrenmeehan Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I've addressed this in f3337db

description = "AWS Lambda Runtime."
edition = "2018"

[features]
Expand Down
2 changes: 1 addition & 1 deletion lambda/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn next_event(req: &Request<Body>) -> Result<Response<Body>, Error> {

let rsp = NextEventResponse {
request_id: "8476a536-e9f4-11e8-9739-2dfe598c3fcd",
deadline: 1542409706888,
deadline: 1_542_409_706_888,
arn: "arn:aws:lambda:us-east-2:123456789012:function:custom-runtime",
trace_id: "Root=1-5bef4de7-ad49b0e87f6ef6c87fc2e700;Parent=9a9197af755a6419",
body: serde_json::to_vec(&body)?,
Expand Down
19 changes: 11 additions & 8 deletions lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

//! The official Rust runtime for AWS Lambda.
//!
//! There are two mechanisms of defining a Lambda function:
//! 1. The `#[lambda]` attribute, which generates the boilerplate needed to
//! to launch and run a Lambda function. The `#[lambda]` attribute _must_
//! be placed on an asynchronous main funtion. However, asynchronous main
//! funtions are not legal valid Rust, which means that a crate like
//! [Runtime](https://github.com/rustasync/runtime) must be used. A main function
//! decorated using `#[lamdba]`
//! 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 `#[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.
//!
Expand Down Expand Up @@ -49,7 +52,7 @@ use std::{
mod client;
mod requests;
mod simulated;
/// Types availible to a Lambda function.
/// Types available to a Lambda function.
mod types;

use requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest};
Expand Down