From d78ce6c0442fa1ad3dbc43b9cabcdd1486a9951c Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 03:31:46 +0800 Subject: [PATCH 1/6] docs: fix missing specified language on codeblock --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 505da34e..86602f2e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ See other installation options in [the Cargo Lambda documentation](https://www.c To create your first function, run Cargo Lambda with the [subcommand `new`](https://www.cargo-lambda.info/commands/new.html). This command will generate a Rust package with the initial source code for your function: -``` +```bash cargo lambda new YOUR_FUNCTION_NAME ``` @@ -72,13 +72,12 @@ async fn func(event: LambdaEvent) -> Result { If you already have Cargo Lambda installed in your machine, run the next command to build your function: -``` +```bash cargo lambda build --release ``` There are other ways of building your function: manually with the AWS CLI, with [AWS SAM](https://github.com/aws/aws-sam-cli), and with the [Serverless framework](https://serverless.com/framework/). - ### 1. Cross-compiling your Lambda functions By default, Cargo Lambda builds your functions to run on x86_64 architectures. If you'd like to use a different architecture, use the options described below. @@ -99,7 +98,7 @@ Amazon Linux 1 uses glibc version 2.17, while Rust binaries need glibc version 2 If you are building for Amazon Linux 1, or you want to support both Amazon Linux 2 and 1, run: -``` +```bash # Note: replace "aarch64" with "x86_64" if you are building for x86_64 cargo lambda build --release --target aarch64-unknown-linux-gnu.2.17 ``` @@ -125,7 +124,6 @@ cargo lambda deploy \ This command will create a Lambda function with the same name of your rust package. You can change the name of the function by adding the argument at the end of the command: - ```bash cargo lambda deploy \ --iam-role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \ @@ -154,7 +152,6 @@ cargo lambda build --release --arm64 --output-format zip You can find the resulting zip file in `target/lambda/YOUR_PACKAGE/bootstrap.zip`. Use that file path to deploy your function with the [AWS CLI](https://aws.amazon.com/cli/): - ```bash $ aws lambda create-function --function-name rustTest \ --handler bootstrap \ @@ -257,7 +254,7 @@ $ npx serverless deploy Invoke it using serverless framework or a configured AWS integrated trigger source: ```bash -$ npx serverless invoke -f hello -d '{"foo":"bar"}' +npx serverless invoke -f hello -d '{"foo":"bar"}' ``` #### 2.5. Docker From fa4c30a1d28c8c5d0e6c3ead5c029cb6b518f1b6 Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 04:09:24 +0800 Subject: [PATCH 2/6] docs: concise examples to perform local testing - use `cargo lambda watch` instead of `start` because `start` is not listed in `cargo lambda --help` - fix incorrect redirect to `cargo lambda watch` instead of `cargo lambda invoke` --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86602f2e..cf6d205c 100644 --- a/README.md +++ b/README.md @@ -328,9 +328,30 @@ fn test_my_lambda_handler() { ### Cargo Lambda -[Cargo Lambda](https://www.cargo-lambda.info) provides a local server that emulates the AWS Lambda control plane. This server works on Windows, Linux, and MacOS. In the root of your Lambda project, run the subcommand `cargo lambda start` to start the server. Your function will be compiled when the server receives the first request to process. Use the subcommand `cargo lambda invoke` to send requests to your function. The `start` subcommand will watch your function's code for changes, and it will compile it every time you save the source after making changes. +[Cargo Lambda](https://www.cargo-lambda.info) provides a local server that emulates the AWS Lambda control plane. This server works on Windows, Linux, and MacOS. In the root of your Lambda project. You can run the following subcommand to compile your function(s) and start the server. -You can read more about how [cargo lambda watch](https://www.cargo-lambda.info/commands/watch.html) and [cargo lambda invoke](https://www.cargo-lambda.info/commands/watch.html) work on the [project's documentation page](https://www.cargo-lambda.info). +```bash +cargo lambda watch -a 127.0.0.1 -p 9001 +``` + +Now you can use the `cargo lambda invoke` to send requests to your function. For example: + +```bash +cargo lambda invoke --data-ascii '{ "command": "hi" }' +``` + +However, this will not work on a HTTP function. Instead, you will have to cURL the following endpoint based on the address and port you defined. For example: + +```bash +curl -v -X POST \ + 'http://127.0.0.1:9001/lambda-url/' \ + -H 'content-type: application/json' \ + -d '{ "command": "hi" }' +``` + +> **warning** Do not remove the `content-type` header. It is necessary to instruct the function how to deserialize the request body. + +You can read more about how [cargo lambda watch](https://www.cargo-lambda.info/commands/watch.html) and [cargo lambda invoke](https://www.cargo-lambda.info/commands/invoke.html) work on the project's [documentation page](https://www.cargo-lambda.info). ### Lambda Debug Proxy From c8502ceeb789c30514f8198887f49962316eacfe Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 04:19:37 +0800 Subject: [PATCH 3/6] docs: fix all non-visual markdown lint errors --- .github/PULL_REQUEST_TEMPLATE.md | 1 - CODE_OF_CONDUCT.md | 5 +++-- CONTRIBUTING.md | 10 ++++------ .../advanced-sqs-partial-batch-failures/README.md | 8 +++----- examples/basic-error-handling/README.md | 4 ++-- examples/basic-lambda/README.md | 4 ++-- examples/basic-shared-resource/README.md | 4 ++-- examples/extension-basic/README.md | 1 - examples/extension-combined/README.md | 1 - examples/extension-custom-events/README.md | 1 - examples/extension-custom-service/README.md | 1 - examples/extension-logs-basic/README.md | 1 - examples/extension-logs-custom-service/README.md | 1 - examples/extension-logs-kinesis-firehose/README.md | 1 - examples/extension-telemetry-basic/README.md | 1 - examples/http-axum/README.md | 4 ++-- examples/http-basic-lambda/README.md | 4 ++-- examples/http-cors/README.md | 4 ++-- examples/http-dynamodb/README.md | 6 ++---- examples/http-query-parameters/README.md | 4 ++-- examples/http-raw-path/README.md | 4 ++-- examples/http-shared-resource/README.md | 4 ++-- lambda-extension/README.md | 9 ++++----- lambda-http/README.md | 13 +++++++------ lambda-runtime-api-client/README.md | 2 +- 25 files changed, 42 insertions(+), 56 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e265aad2..31b151e5 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,6 @@ *Description of changes:* - By submitting this pull request - [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 3b644668..ec98f2b7 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,4 +1,5 @@ ## Code of Conduct -This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). -For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact + +This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact opensource-codeofconduct@amazon.com with any additional questions or comments. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09a50434..9b87d31f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,6 @@ documentation, we greatly value feedback and contributions from our community. Please read through this document before submitting any issues or pull requests to ensure we have all the necessary information to effectively respond to your bug report or contribution. - ## Reporting Bugs/Feature Requests We welcome you to use the GitHub issue tracker to report bugs or suggest features. @@ -19,8 +18,8 @@ reported the issue. Please try to include as much information as you can. Detail * Any modifications you've made relevant to the bug * Anything unusual about your environment or deployment - ## Contributing via Pull Requests + Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 1. You are working against the latest source on the *main* branch. @@ -39,20 +38,19 @@ To send us a pull request, please: GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). - ## Finding contributions to work on -Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-lambda-rust-runtime/labels/help%20wanted) issues is a great place to start. +Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/awslabs/aws-lambda-rust-runtime/labels/help%20wanted) issues is a great place to start. ## Code of Conduct + This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact opensource-codeofconduct@amazon.com with any additional questions or comments. - ## Security issue notifications -If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. +If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. ## Licensing diff --git a/examples/advanced-sqs-partial-batch-failures/README.md b/examples/advanced-sqs-partial-batch-failures/README.md index 7b10ca50..9711db8b 100644 --- a/examples/advanced-sqs-partial-batch-failures/README.md +++ b/examples/advanced-sqs-partial-batch-failures/README.md @@ -2,10 +2,8 @@ This example shows how to process events from an SQS queue using the partial batch failure feature. -_Important note:_ your lambda sqs trigger *needs* to be configured with partial batch response support -(the ` ReportBatchItemFailures` flag set to true), otherwise failed message will be not be reprocessed. -For more details see: -https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting +_Important note:_ your lambda sqs trigger _needs_ to be configured with partial batch response support +(the `ReportBatchItemFailures` flag set to true), otherwise failed message will be not be reprocessed. You may see more details [here](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting). ## Build & Deploy @@ -15,4 +13,4 @@ https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfai ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` \ No newline at end of file +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/basic-error-handling/README.md b/examples/basic-error-handling/README.md index 5cae85fb..498f8a50 100644 --- a/examples/basic-error-handling/README.md +++ b/examples/basic-error-handling/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/basic-lambda/README.md b/examples/basic-lambda/README.md index 5cae85fb..498f8a50 100644 --- a/examples/basic-lambda/README.md +++ b/examples/basic-lambda/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/basic-shared-resource/README.md b/examples/basic-shared-resource/README.md index 5cae85fb..498f8a50 100644 --- a/examples/basic-shared-resource/README.md +++ b/examples/basic-shared-resource/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/extension-basic/README.md b/examples/extension-basic/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-basic/README.md +++ b/examples/extension-basic/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-combined/README.md b/examples/extension-combined/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-combined/README.md +++ b/examples/extension-combined/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-custom-events/README.md b/examples/extension-custom-events/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-custom-events/README.md +++ b/examples/extension-custom-events/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-custom-service/README.md b/examples/extension-custom-service/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-custom-service/README.md +++ b/examples/extension-custom-service/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-logs-basic/README.md b/examples/extension-logs-basic/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-logs-basic/README.md +++ b/examples/extension-logs-basic/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-logs-custom-service/README.md b/examples/extension-logs-custom-service/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-logs-custom-service/README.md +++ b/examples/extension-logs-custom-service/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-logs-kinesis-firehose/README.md b/examples/extension-logs-kinesis-firehose/README.md index 6f9636c9..b566774e 100644 --- a/examples/extension-logs-kinesis-firehose/README.md +++ b/examples/extension-logs-kinesis-firehose/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/extension-telemetry-basic/README.md b/examples/extension-telemetry-basic/README.md index fe9c26ca..337e045c 100644 --- a/examples/extension-telemetry-basic/README.md +++ b/examples/extension-telemetry-basic/README.md @@ -8,7 +8,6 @@ The last command will give you an ARN for the extension layer that you can use in your functions. - ## Build for ARM 64 Build the extension with `cargo lambda build --release --extension --arm64` diff --git a/examples/http-axum/README.md b/examples/http-axum/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-axum/README.md +++ b/examples/http-axum/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/http-basic-lambda/README.md b/examples/http-basic-lambda/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-basic-lambda/README.md +++ b/examples/http-basic-lambda/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/http-cors/README.md b/examples/http-cors/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-cors/README.md +++ b/examples/http-cors/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/http-dynamodb/README.md b/examples/http-dynamodb/README.md index cb53c868..072f2bf9 100644 --- a/examples/http-dynamodb/README.md +++ b/examples/http-dynamodb/README.md @@ -3,17 +3,15 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` Setting up Dynamodb 1. Log into your account. 2. Create a Dynamodb table with the name 'lambda_dyno_example' with the partition key of "username". 3. Create IAM role with the permissions for Lambda, Cloudwatch and Dynamodb. - - diff --git a/examples/http-query-parameters/README.md b/examples/http-query-parameters/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-query-parameters/README.md +++ b/examples/http-query-parameters/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/http-raw-path/README.md b/examples/http-raw-path/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-raw-path/README.md +++ b/examples/http-raw-path/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/examples/http-shared-resource/README.md b/examples/http-shared-resource/README.md index 5cae85fb..498f8a50 100644 --- a/examples/http-shared-resource/README.md +++ b/examples/http-shared-resource/README.md @@ -3,9 +3,9 @@ ## Build & Deploy 1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation) -2. Build the function with `cargo lambda build --release` +2. Build the function with `cargo lambda build --release` 3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE` ## Build for ARM 64 -Build the function with `cargo lambda build --release --arm64` +Build the function with `cargo lambda build --release --arm64` diff --git a/lambda-extension/README.md b/lambda-extension/README.md index b3f5e529..00cd77c4 100644 --- a/lambda-extension/README.md +++ b/lambda-extension/README.md @@ -125,13 +125,13 @@ Regardless of how you deploy them, the extensions MUST be compiled against the s - Build the extension with: -``` +```bash cargo lambda build --release --extension ``` If you want to run the extension in ARM processors, add the `--arm64` flag to the previous command: -``` +```bash cargo lambda build --release --extension --arm64 ``` @@ -141,13 +141,12 @@ This previous command will generate a binary file in `target/lambda/extensions` - Make sure you have the right credentials in your terminal by running the AWS CLI configure command: -``` +```bash aws configure ``` - Deploy the extension as a layer with: -``` +```bash cargo lambda deploy --extension ``` - diff --git a/lambda-http/README.md b/lambda-http/README.md index 20e670eb..1eef90c6 100644 --- a/lambda-http/README.md +++ b/lambda-http/README.md @@ -1,14 +1,16 @@ # lambda-http for AWS Lambda in Rust -[![Docs](https://docs.rs/lambda_http/badge.svg)](https://docs.rs/lambda_http) +[![Docs](https://docs.rs/lambda_http/badge.svg)](https://docs.rs/lambda_http) **`lambda-http`** is an abstraction that takes payloads from different services and turns them into http objects, making it easy to write API Gateway proxy event focused Lambda functions in Rust. lambda-http handler is made of: + * Request - Represents an HTTP request * IntoResponse - Future that will convert an [`IntoResponse`] into an actual [`LambdaResponse`] We are able to handle requests from: + * [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) REST, HTTP and WebSockets API lambda integrations * AWS [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html) * AWS [Lambda function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html) @@ -61,7 +63,7 @@ pub async fn function_handler(event: Request) -> Result Result Result<(), Error> { client.call(request).await } -``` \ No newline at end of file +``` From 17c5d7670f7098bf6737428e6abe326316678bdc Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 04:39:05 +0800 Subject: [PATCH 4/6] refactor: use non-deprecated `with_ymd_and_hms` --- lambda-extension/src/logs.rs | 8 ++++++-- lambda-extension/src/telemetry.rs | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lambda-extension/src/logs.rs b/lambda-extension/src/logs.rs index cdb6ed31..cf894100 100644 --- a/lambda-extension/src/logs.rs +++ b/lambda-extension/src/logs.rs @@ -184,13 +184,17 @@ where #[cfg(test)] mod tests { use super::*; - use chrono::TimeZone; + use chrono::{Duration, TimeZone}; #[test] fn deserialize_full() { let data = r#"{"time": "2020-08-20T12:31:32.123Z","type": "function", "record": "hello world"}"#; let expected = LambdaLog { - time: Utc.ymd(2020, 8, 20).and_hms_milli(12, 31, 32, 123), + time: Utc + .with_ymd_and_hms(2020, 8, 20, 12, 31, 32) + .unwrap() + .checked_add_signed(Duration::milliseconds(123)) + .unwrap(), record: LambdaLogRecord::Function("hello world".to_string()), }; diff --git a/lambda-extension/src/telemetry.rs b/lambda-extension/src/telemetry.rs index e8b66bd3..b3131338 100644 --- a/lambda-extension/src/telemetry.rs +++ b/lambda-extension/src/telemetry.rs @@ -301,7 +301,7 @@ where #[cfg(test)] mod tests { use super::*; - use chrono::TimeZone; + use chrono::{Duration, TimeZone}; macro_rules! deserialize_tests { ($($name:ident: $value:expr,)*) => { @@ -367,13 +367,21 @@ mod tests { spans: vec!( Span { name:"responseLatency".to_string(), - start: Utc.ymd(2022, 10, 21).and_hms_milli(14, 05, 03, 165), - duration_ms:2598.0 + start: Utc + .with_ymd_and_hms(2022, 10, 21, 14, 5, 3) + .unwrap() + .checked_add_signed(Duration::milliseconds(165)) + .unwrap(), + duration_ms: 2598.0 }, Span { name:"responseDuration".to_string(), - start:Utc.ymd(2022, 10, 21).and_hms_milli(14, 05, 05, 763), - duration_ms:0.0 + start: Utc + .with_ymd_and_hms(2022, 10, 21, 14, 5, 5) + .unwrap() + .checked_add_signed(Duration::milliseconds(763)) + .unwrap(), + duration_ms: 0.0 }, ), tracing: Some(TraceContext{ From c2951faae8ddb7cc789623db47b5c88ca32829dd Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 05:04:30 +0800 Subject: [PATCH 5/6] docs: add example of the error received --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf6d205c..5e7a5b3a 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,15 @@ Now you can use the `cargo lambda invoke` to send requests to your function. For cargo lambda invoke --data-ascii '{ "command": "hi" }' ``` -However, this will not work on a HTTP function. Instead, you will have to cURL the following endpoint based on the address and port you defined. For example: +Running the command on a HTTP function (Function URL, API Gateway, etc) will not work, presenting you with the following error. + +```rust,no_run +Error: serde_json::error::Error + + × data did not match any variant of untagged enum LambdaRequest +``` + +Instead, you will have to cURL the following endpoint based on the address and port you defined. For example: ```bash curl -v -X POST \ From 81be74cdaaef8d4144517003ab0b075468ff6c5b Mon Sep 17 00:00:00 2001 From: winstxnhdw Date: Sat, 18 Feb 2023 16:19:27 +0800 Subject: [PATCH 6/6] docs: fix incorrect detail on the `invoke` command --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e7a5b3a..f4befe1d 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,7 @@ Now you can use the `cargo lambda invoke` to send requests to your function. For cargo lambda invoke --data-ascii '{ "command": "hi" }' ``` -Running the command on a HTTP function (Function URL, API Gateway, etc) will not work, presenting you with the following error. +Running the command on a HTTP function (Function URL, API Gateway, etc) will require you to use the appropriate scheme. You can find examples of these schemes [here](https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/lambda-http/tests/data). Otherwise, you will be presented with the following error. ```rust,no_run Error: serde_json::error::Error @@ -348,7 +348,7 @@ Error: serde_json::error::Error × data did not match any variant of untagged enum LambdaRequest ``` -Instead, you will have to cURL the following endpoint based on the address and port you defined. For example: +An simpler alternative is to cURL the following endpoint based on the address and port you defined. For example: ```bash curl -v -X POST \