From 629c5b72021f91bc9df8dbffdd7eb0950ad91e84 Mon Sep 17 00:00:00 2001 From: edmuthiah Date: Sun, 19 Feb 2023 02:28:47 +1100 Subject: [PATCH 1/7] Fix invoke example for Windows --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4befe1d..c9b02a20 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ 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" }' +cargo lambda invoke --data-ascii "{\"command\": \"hi\" }" ``` 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. From e685b1cdc9fd1f8ebf0da86847679ae69a67126b Mon Sep 17 00:00:00 2001 From: edmuthiah Date: Sun, 19 Feb 2023 10:20:56 +1100 Subject: [PATCH 2/7] Fix invoke example for Windows CMD --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9b02a20..f8c20887 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ You can test the function with the [invoke subcommand](https://www.cargo-lambda. ```bash cargo lambda invoke --remote \ - --data-ascii '{"command": "hi"}' \ + --data-ascii "{\"command\": \"hi\" }" \ --output-format json \ my-first-lambda-function ``` @@ -171,7 +171,7 @@ You can now test the function using the AWS CLI or the AWS Lambda console $ aws lambda invoke --cli-binary-format raw-in-base64-out \ --function-name rustTest \ - --payload '{"command": "Say Hi!"}' \ + --payload "{\"command\": \"hi\" }" \ output.json $ cat output.json # Prints: {"msg": "Command Say Hi! executed."} ``` @@ -218,7 +218,7 @@ At the end, `sam` will output the actual Lambda function name. You can use this $ aws lambda invoke --cli-binary-format raw-in-base64-out \ --function-name HelloWorldFunction-XXXXXXXX \ # Replace with the actual function name - --payload '{"command": "Say Hi!"}' \ + --payload "{\"command\": \"hi\" }" \ output.json $ cat output.json # Prints: {"msg": "Command Say Hi! executed."} ``` @@ -254,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 37230f732534f00948707535e57d7b3bf185bd87 Mon Sep 17 00:00:00 2001 From: edmuthiah Date: Sun, 19 Feb 2023 10:28:33 +1100 Subject: [PATCH 3/7] Fix invoke example for Windows CMD --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8c20887..d7960384 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ An simpler alternative is to cURL the following endpoint based on the address an curl -v -X POST \ 'http://127.0.0.1:9001/lambda-url/' \ -H 'content-type: application/json' \ - -d '{ "command": "hi" }' + -d "{\"command\": \"hi\" }" ``` > **warning** Do not remove the `content-type` header. It is necessary to instruct the function how to deserialize the request body. From 14e1e07136871e7b7c0fbf3e33c3cdbe8c683327 Mon Sep 17 00:00:00 2001 From: edmuthiah Date: Wed, 22 Feb 2023 01:57:07 +1100 Subject: [PATCH 4/7] Add note on handling quotes in different shells --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d7960384..53833b98 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ async fn func(event: LambdaEvent) -> Result { ``` ## Building and deploying your Lambda functions +> **Note** +> The CLI commands in the following examples are written in Linux/MacOS syntax. If you are using a different shell, such as Windows CMD or PowerShell, you may need to modify the quotation format when using quotation marks inside nested strings, such as `'{"command": "hi"}'`. For example, you might need to escape the quotes with a backslash. For more information on modifying commands, please see the [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing). If you already have Cargo Lambda installed in your machine, run the next command to build your function: @@ -137,7 +139,7 @@ You can test the function with the [invoke subcommand](https://www.cargo-lambda. ```bash cargo lambda invoke --remote \ - --data-ascii "{\"command\": \"hi\" }" \ + --data-ascii '{"command": "hi"}' \ --output-format json \ my-first-lambda-function ``` @@ -171,7 +173,7 @@ You can now test the function using the AWS CLI or the AWS Lambda console $ aws lambda invoke --cli-binary-format raw-in-base64-out \ --function-name rustTest \ - --payload "{\"command\": \"hi\" }" \ + --payload '{"command": "Say Hi!"}' \ output.json $ cat output.json # Prints: {"msg": "Command Say Hi! executed."} ``` @@ -218,7 +220,7 @@ At the end, `sam` will output the actual Lambda function name. You can use this $ aws lambda invoke --cli-binary-format raw-in-base64-out \ --function-name HelloWorldFunction-XXXXXXXX \ # Replace with the actual function name - --payload "{\"command\": \"hi\" }" \ + --payload '{"command": "Say Hi!"}' \ output.json $ cat output.json # Prints: {"msg": "Command Say Hi! executed."} ``` @@ -254,7 +256,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 @@ -337,7 +339,7 @@ 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\" }" +cargo lambda invoke --data-ascii '{ "command": "hi" }' ``` 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. @@ -354,7 +356,7 @@ An simpler alternative is to cURL the following endpoint based on the address an curl -v -X POST \ 'http://127.0.0.1:9001/lambda-url/' \ -H 'content-type: application/json' \ - -d "{\"command\": \"hi\" }" + -d '{ "command": "hi" }' ``` > **warning** Do not remove the `content-type` header. It is necessary to instruct the function how to deserialize the request body. From 0e18f64097bda62031da020160bc807d7c4cb1fd Mon Sep 17 00:00:00 2001 From: edmuthiah Date: Wed, 22 Feb 2023 02:02:04 +1100 Subject: [PATCH 5/7] Add shorter note on handling quotes in different shells --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53833b98..094fc59c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ async fn func(event: LambdaEvent) -> Result { ## Building and deploying your Lambda functions > **Note** -> The CLI commands in the following examples are written in Linux/MacOS syntax. If you are using a different shell, such as Windows CMD or PowerShell, you may need to modify the quotation format when using quotation marks inside nested strings, such as `'{"command": "hi"}'`. For example, you might need to escape the quotes with a backslash. For more information on modifying commands, please see the [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing). +> CLI commands in the examples use Linux/MacOS syntax. For different shells like Windows CMD or PowerShell, modify syntax when using nested quotation marks like `'{"command": "hi"}'`. Escaping with a backslash may be necessary. See [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing) for more information. If you already have Cargo Lambda installed in your machine, run the next command to build your function: From 9465013c69347e6323a76cea1ed5ae0fed2c466f Mon Sep 17 00:00:00 2001 From: Ed Muthiah Date: Tue, 21 Feb 2023 21:45:10 -0800 Subject: [PATCH 6/7] Moved note closer to first invoke --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 094fc59c..f4befe1d 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,6 @@ async fn func(event: LambdaEvent) -> Result { ``` ## Building and deploying your Lambda functions -> **Note** -> CLI commands in the examples use Linux/MacOS syntax. For different shells like Windows CMD or PowerShell, modify syntax when using nested quotation marks like `'{"command": "hi"}'`. Escaping with a backslash may be necessary. See [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing) for more information. If you already have Cargo Lambda installed in your machine, run the next command to build your function: From 65c1adc6b10e791c08ac44c69ebd0af2bd804017 Mon Sep 17 00:00:00 2001 From: Ed Muthiah Date: Tue, 21 Feb 2023 21:47:43 -0800 Subject: [PATCH 7/7] moved note closer to invoke --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f4befe1d..2cc04fb3 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ cargo lambda invoke --remote \ my-first-lambda-function ``` +> **Note** +> CLI commands in the examples use Linux/MacOS syntax. For different shells like Windows CMD or PowerShell, modify syntax when using nested quotation marks like `'{"command": "hi"}'`. Escaping with a backslash may be necessary. See [AWS CLI Reference](https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-usage-parameters-quoting-strings.html#cli-usage-parameters-quoting-strings-containing) for more information. + #### 2.2. Deploying with the AWS CLI You can also use the AWS CLI to deploy your Rust functions. First, you will need to create a ZIP archive of your function. Cargo Lambda can do that for you automatically when it builds your binary if you add the `output-format` flag: