From c1e71e27221fd64d777f5dec1f9eb0f50ba168ab Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Mon, 27 Apr 2020 21:34:03 +0100 Subject: [PATCH 01/14] Fix minor typos --- lambda/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index b9b5aa2e..0888dd5f 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -6,10 +6,10 @@ //! 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 +//! be placed on an asynchronous main function. However, asynchronous main +//! functions 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]` +//! decorated using `#[lambdas]` //! 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. //! From 1180ed1a5361a7ba73ff2487c38090744b5d0597 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Mon, 27 Apr 2020 21:41:18 +0100 Subject: [PATCH 02/14] Avoid long literal lacking separators --- lambda/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)?, From 6f807804a65a3951a8718252c38ddd5e66405e65 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Mon, 27 Apr 2020 21:42:07 +0100 Subject: [PATCH 03/14] Add description --- lambda/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 6e3c3c7e..34b7f38c 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 client." edition = "2018" [features] From 1e250dd9a3a5335b569f1c9d63ed5a80ca4429c4 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 13:21:47 +0100 Subject: [PATCH 04/14] Update README to use hello world example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76aeb464..d7b1b451 100644 --- a/README.md +++ b/README.md @@ -62,13 +62,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! From f2dd59c4c997d590061a3b93bdfbe262cbf5a486 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 13:22:23 +0100 Subject: [PATCH 05/14] Update cli changes to work with aws cli v2 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7b1b451..bbceb675 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,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} \ @@ -87,6 +87,7 @@ You can now test the function using the AWS CLI or the AWS Lambda console ```bash $ aws lambda invoke --function-name rustTest \ + --cli-binary-format raw-in-base64-out \ --payload '{"firstName": "world"}' \ output.json $ cat output.json # Prints: {"message":"Hello, world!"} From 0d2872e01b1a5601f8db2dfc9cd59e3f7772588e Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 13:24:11 +0100 Subject: [PATCH 06/14] Ignore outputs from follow instructions --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 From 8a76469096a39584beae8a941703ca688fd5f00c Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 13:35:30 +0100 Subject: [PATCH 07/14] Remove Travis button as it's no longer used. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 76aeb464..ba3aca75 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! From f3337dbd35194865f8d476fa4cf3448265864dc4 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 22:33:54 +0100 Subject: [PATCH 08/14] Remove client from description This is a closer fit to the convention for runtimes across different languages. --- lambda/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 34b7f38c..55743509 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -2,7 +2,7 @@ name = "lambda" version = "0.1.0" authors = ["David Barsky "] -description = "AWS Lambda runtime client." +description = "AWS Lambda runtime." edition = "2018" [features] From 6bb60b97daab58f088b23294df9fe0ba1a8df2f0 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 22:36:06 +0100 Subject: [PATCH 09/14] Capitalise runtime in description --- lambda/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/Cargo.toml b/lambda/Cargo.toml index 55743509..b3b82041 100644 --- a/lambda/Cargo.toml +++ b/lambda/Cargo.toml @@ -2,7 +2,7 @@ name = "lambda" version = "0.1.0" authors = ["David Barsky "] -description = "AWS Lambda runtime." +description = "AWS Lambda Runtime." edition = "2018" [features] From 56a745f0c9b87b9dc2ef369846f60a771da0bc17 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Tue, 28 Apr 2020 22:40:55 +0100 Subject: [PATCH 10/14] Document --cli-binary-format seperately Most users are still using v2 of the cli. Let's keep things simple for them. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 905fb65f..12882634 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,14 @@ You can now test the function using the AWS CLI or the AWS Lambda console ```bash $ aws lambda invoke --function-name rustTest \ - --cli-binary-format raw-in-base64-out \ --payload '{"firstName": "world"}' \ output.json $ 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). From 1ef54a8a7f5502dee7b6763b18d9e536f4f237a3 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Wed, 29 Apr 2020 16:18:27 +0100 Subject: [PATCH 11/14] Fixed name for macro Also expanded on comment Co-Authored-By: David Barsky --- lambda/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 0888dd5f..2b103035 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -9,7 +9,7 @@ //! be placed on an asynchronous main function. However, asynchronous main //! functions 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 `#[lambdas]` +//! decorated using a `#[lambda]` attribute macro. //! 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. //! From 00f59dbd5bf62cce61ea4b8c1a2e3a32bd2d8b91 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Wed, 29 Apr 2020 17:27:42 +0100 Subject: [PATCH 12/14] Fix typo --- lambda/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 2b103035..caa77ac8 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -49,7 +49,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}; From d508b923cdabf3e4a98b4a13845007e2a0810536 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Wed, 29 Apr 2020 17:33:00 +0100 Subject: [PATCH 13/14] Highlight tokia requirement and improve clarity --- lambda/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index caa77ac8..89516212 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 function. However, asynchronous main -//! functions 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 a `#[lambda]` attribute macro. +//! 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. //! From 7dea46450f831c8d677f85e9ab2ba650c84dbf31 Mon Sep 17 00:00:00 2001 From: Darren Meehan Date: Wed, 29 Apr 2020 17:35:58 +0100 Subject: [PATCH 14/14] Address whitespace issue --- lambda/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambda/src/lib.rs b/lambda/src/lib.rs index 89516212..f0af515c 100644 --- a/lambda/src/lib.rs +++ b/lambda/src/lib.rs @@ -6,13 +6,13 @@ //! 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. //!