Skip to content

Commit 26b330d

Browse files
authored
docs/refactor: add documentation for invoking HTTP functions locally (#601)
* docs: fix missing specified language on codeblock * 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` * docs: fix all non-visual markdown lint errors * refactor: use non-deprecated `with_ymd_and_hms` * docs: add example of the error received * docs: fix incorrect detail on the `invoke` command
1 parent a2386b9 commit 26b330d

File tree

28 files changed

+96
-72
lines changed

28 files changed

+96
-72
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
*Description of changes:*
44

5-
65
By submitting this pull request
76

87
- [ ] I confirm that my contribution is made under the terms of the Apache 2.0 license.

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Code of Conduct
2-
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3-
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
2+
3+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
4+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
45
[email protected] with any additional questions or comments.

CONTRIBUTING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ documentation, we greatly value feedback and contributions from our community.
66
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9-
109
## Reporting Bugs/Feature Requests
1110

1211
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
1918
* Any modifications you've made relevant to the bug
2019
* Anything unusual about your environment or deployment
2120

22-
2321
## Contributing via Pull Requests
22+
2423
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2524

2625
1. You are working against the latest source on the *main* branch.
@@ -39,20 +38,19 @@ To send us a pull request, please:
3938
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4039
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4140

42-
4341
## Finding contributions to work on
44-
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.
4542

43+
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.
4644

4745
## Code of Conduct
46+
4847
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
4948
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
5049
[email protected] with any additional questions or comments.
5150

52-
5351
## Security issue notifications
54-
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.
5552

53+
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.
5654

5755
## Licensing
5856

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ See other installation options in [the Cargo Lambda documentation](https://www.c
4141

4242
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:
4343

44-
```
44+
```bash
4545
cargo lambda new YOUR_FUNCTION_NAME
4646
```
4747

@@ -72,13 +72,12 @@ async fn func(event: LambdaEvent<Value>) -> Result<Value, Error> {
7272

7373
If you already have Cargo Lambda installed in your machine, run the next command to build your function:
7474

75-
```
75+
```bash
7676
cargo lambda build --release
7777
```
7878

7979
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/).
8080

81-
8281
### 1. Cross-compiling your Lambda functions
8382

8483
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
9998

10099
If you are building for Amazon Linux 1, or you want to support both Amazon Linux 2 and 1, run:
101100

102-
```
101+
```bash
103102
# Note: replace "aarch64" with "x86_64" if you are building for x86_64
104103
cargo lambda build --release --target aarch64-unknown-linux-gnu.2.17
105104
```
@@ -125,7 +124,6 @@ cargo lambda deploy \
125124
This command will create a Lambda function with the same name of your rust package. You can change the name
126125
of the function by adding the argument at the end of the command:
127126

128-
129127
```bash
130128
cargo lambda deploy \
131129
--iam-role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \
@@ -154,7 +152,6 @@ cargo lambda build --release --arm64 --output-format zip
154152

155153
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/):
156154

157-
158155
```bash
159156
$ aws lambda create-function --function-name rustTest \
160157
--handler bootstrap \
@@ -257,7 +254,7 @@ $ npx serverless deploy
257254
Invoke it using serverless framework or a configured AWS integrated trigger source:
258255

259256
```bash
260-
$ npx serverless invoke -f hello -d '{"foo":"bar"}'
257+
npx serverless invoke -f hello -d '{"foo":"bar"}'
261258
```
262259

263260
#### 2.5. Docker
@@ -331,9 +328,38 @@ fn test_my_lambda_handler() {
331328

332329
### Cargo Lambda
333330

334-
[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.
331+
[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.
332+
333+
```bash
334+
cargo lambda watch -a 127.0.0.1 -p 9001
335+
```
336+
337+
Now you can use the `cargo lambda invoke` to send requests to your function. For example:
338+
339+
```bash
340+
cargo lambda invoke <lambda-function-name> --data-ascii '{ "command": "hi" }'
341+
```
342+
343+
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.
344+
345+
```rust,no_run
346+
Error: serde_json::error::Error
347+
348+
× data did not match any variant of untagged enum LambdaRequest
349+
```
350+
351+
An simpler alternative is to cURL the following endpoint based on the address and port you defined. For example:
352+
353+
```bash
354+
curl -v -X POST \
355+
'http://127.0.0.1:9001/lambda-url/<lambda-function-name>' \
356+
-H 'content-type: application/json' \
357+
-d '{ "command": "hi" }'
358+
```
359+
360+
> **warning** Do not remove the `content-type` header. It is necessary to instruct the function how to deserialize the request body.
335361
336-
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).
362+
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).
337363

338364
### Lambda Debug Proxy
339365

examples/advanced-sqs-partial-batch-failures/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
This example shows how to process events from an SQS queue using the partial batch failure feature.
44

5-
_Important note:_ your lambda sqs trigger *needs* to be configured with partial batch response support
6-
(the ` ReportBatchItemFailures` flag set to true), otherwise failed message will be not be reprocessed.
7-
For more details see:
8-
https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting
5+
_Important note:_ your lambda sqs trigger _needs_ to be configured with partial batch response support
6+
(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).
97

108
## Build & Deploy
119

@@ -15,4 +13,4 @@ https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfai
1513

1614
## Build for ARM 64
1715

18-
Build the function with `cargo lambda build --release --arm64`
16+
Build the function with `cargo lambda build --release --arm64`

examples/basic-error-handling/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/basic-lambda/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/basic-shared-resource/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/extension-basic/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-combined/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-custom-events/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-custom-service/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-logs-basic/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-logs-custom-service/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-logs-kinesis-firehose/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/extension-telemetry-basic/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
The last command will give you an ARN for the extension layer that you can use in your functions.
1010

11-
1211
## Build for ARM 64
1312

1413
Build the extension with `cargo lambda build --release --extension --arm64`

examples/http-axum/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/http-basic-lambda/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/http-cors/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/http-dynamodb/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`
1212

1313
Setting up Dynamodb
1414

1515
1. Log into your account.
1616
2. Create a Dynamodb table with the name 'lambda_dyno_example' with the partition key of "username".
1717
3. Create IAM role with the permissions for Lambda, Cloudwatch and Dynamodb.
18-
19-

examples/http-query-parameters/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/http-raw-path/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

examples/http-shared-resource/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## Build & Deploy
44

55
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6-
2. Build the function with `cargo lambda build --release`
6+
2. Build the function with `cargo lambda build --release`
77
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
88

99
## Build for ARM 64
1010

11-
Build the function with `cargo lambda build --release --arm64`
11+
Build the function with `cargo lambda build --release --arm64`

0 commit comments

Comments
 (0)