diff --git a/.gitignore b/.gitignore index bc2b2fc1..911cf87c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ /target /.cargo -lambda-runtime/libtest.rmeta \ No newline at end of file +lambda-runtime/libtest.rmeta + +# Built AWS Lambda zipfile +lambda.zip + +# output.json from example docs +output.json diff --git a/README.md b/README.md index 76aeb464..12882634 100644 --- a/README.md +++ b/README.md @@ -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! @@ -62,13 +60,13 @@ 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! @@ -76,7 +74,7 @@ Now that we have a deployment package (`lambda.zip`), we can use the [AWS CLI](h ```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} \ @@ -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). diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 6e3c3c7e..b3b82041 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -2,6 +2,7 @@ name = "lambda" version = "0.1.0" authors = ["David Barsky "] +description = "AWS Lambda Runtime." edition = "2018" [features] diff --git a/lambda/src/client.rs b/lambda/src/client.rs index ff518241..8d0ddb58 100644 --- a/lambda/src/client.rs +++ b/lambda/src/client.rs @@ -111,7 +111,7 @@ async fn next_event(req: &Request) -> Result, 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)?, diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index b9b5aa2e..f0af515c 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -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. //! @@ -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};