You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Remove old tooling information that we don't test or use.
- Update to recommend AL2023
- Remove any mention to AL1
- Cleanup code examples
- Move lambda_http specific docs to its own readme
Signed-off-by: David Calavera <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+6-112Lines changed: 6 additions & 112 deletions
Original file line number
Diff line number
Diff line change
@@ -87,25 +87,14 @@ By default, Cargo Lambda builds your functions to run on x86_64 architectures. I
87
87
88
88
#### 1.2. Build your Lambda functions
89
89
90
-
__Amazon Linux 2__
90
+
__Amazon Linux 2023__
91
91
92
-
We recommend you to use Amazon Linux 2 runtimes (such as `provided.al2`) as much as possible for building Lambda functions in Rust. To build your Lambda functions for Amazon Linux 2 runtimes, run:
92
+
We recommend you to use the Amazon Linux 2023 (such as `provided.al2023`) because it includes a newer version of GLIC, which many Rust programs depend on. To build your Lambda functions for Amazon Linux 2023 runtimes, run:
93
93
94
94
```bash
95
95
cargo lambda build --release --arm64
96
96
```
97
97
98
-
__Amazon Linux 1__
99
-
100
-
Amazon Linux 1 uses glibc version 2.17, while Rust binaries need glibc version 2.18 or later by default. However, with Cargo Lambda, you can specify a different version of glibc.
101
-
102
-
If you are building for Amazon Linux 1, or you want to support both Amazon Linux 2 and 1, run:
> Replace "aarch64" with "x86_64" if you are building for x86_64
109
98
### 2. Deploying the binary to AWS Lambda
110
99
111
100
For [a custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html), AWS Lambda looks for an executable called `bootstrap` in the deployment package zip. Rename the generated executable to `bootstrap` and add it to a zip archive.
@@ -117,8 +106,7 @@ You can find the `bootstrap` binary for your function under the `target/lambda`
117
106
Once you've built your code with one of the options described earlier, use the `deploy` subcommand to upload your function to AWS:
$ cat output.json # Prints: {"msg": "Command Say Hi! executed."}
230
216
```
231
217
232
-
#### 2.4. Serverless Framework
233
-
234
-
Alternatively, you can build a Rust-based Lambda function declaratively using the [Serverless framework Rust plugin](https://github.com/softprops/serverless-rust).
235
-
236
-
A number of getting started Serverless application templates exist to get you up and running quickly:
237
-
238
-
- a minimal [echo function](https://github.com/softprops/serverless-aws-rust) to demonstrate what the smallest Rust function setup looks like
239
-
- a minimal [http function](https://github.com/softprops/serverless-aws-rust-http) to demonstrate how to interface with API Gateway using Rust's native [http](https://crates.io/crates/http) crate (note this will be a git dependency until 0.2 is published)
240
-
- a combination [multi function service](https://github.com/softprops/serverless-aws-rust-multi) to demonstrate how to set up a services with multiple independent functions
241
-
242
-
Assuming your host machine has a relatively recent version of node, you [won't need to install any host-wide serverless dependencies](https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner). To get started, run the following commands to create a new lambda Rust application
# build, package, and deploy service to aws lambda
257
-
$ npx serverless deploy
258
-
```
259
-
260
-
Invoke it using serverless framework or a configured AWS integrated trigger source:
261
-
262
-
```bash
263
-
npx serverless invoke -f hello -d '{"foo":"bar"}'
264
-
```
265
-
266
-
#### 2.5. Docker
267
-
268
-
Alternatively, you can build a Rust-based Lambda function in a [docker mirror of the AWS Lambda provided runtime with the Rust toolchain preinstalled](https://github.com/rust-serverless/lambda-rust).
269
-
270
-
Running the following command will start an ephemeral docker container, which will build your Rust application and produce a zip file containing its binary auto-renamed to `bootstrap` to meet the AWS Lambda's expectations for binaries under `target/lambda_runtime/release/{your-binary-name}.zip`. Typically, this is just the name of your crate if you are using the cargo default binary (i.e. `main.rs`):
With your application built and packaged, it's ready to ship to production. You can also invoke it locally to verify is behavior using the [lambci :provided docker container](https://hub.docker.com/r/lambci/lambda/), which is also a mirror of the AWS Lambda provided runtime with build dependencies omitted:
282
-
283
-
```bash
284
-
# start a docker container replicating the "provided" lambda runtime
285
-
# awaiting an event to be provided via stdin
286
-
$ unzip -o \
287
-
target/lambda/release/{your-binary-name}.zip \
288
-
-d /tmp/lambda && \
289
-
docker run \
290
-
-i -e DOCKER_LAMBDA_USE_STDIN=1 \
291
-
--rm \
292
-
-v /tmp/lambda:/var/task \
293
-
lambci/lambda:provided
294
-
295
-
# provide an event payload via stdin (typically a json blob)
296
-
297
-
# Ctrl-D to yield control back to your function
298
-
```
299
-
300
218
## Local development and testing
301
219
302
220
### Testing your code with unit and integration tests
@@ -332,7 +250,7 @@ fn test_my_lambda_handler() {
332
250
}
333
251
```
334
252
335
-
### Cargo Lambda
253
+
### Local dev server with Cargo Lambda
336
254
337
255
[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.
`lambda_http` is a wrapper for HTTP events coming from three different services, Amazon Load Balancer (ALB), Amazon Api Gateway (APIGW), and AWS Lambda Function URLs. Amazon Api Gateway can also send events from three different endpoints, REST APIs, HTTP APIs, and WebSockets. `lambda_http` transforms events from all these sources into native `http::Request` objects, so you can incorporate Rust HTTP semantics into your Lambda functions.
438
-
439
-
By default, `lambda_http` compiles your function to support any of those services. This increases the compile time of your function because we have to generate code for all the sources. In reality, you'll usually put a Lambda function only behind one of those sources. You can choose which source to generate code for with feature flags.
440
-
441
-
The available features flags for `lambda_http` are the following:
442
-
443
-
-`alb`: for events coming from [Amazon Elastic Load Balancer](https://aws.amazon.com/elasticloadbalancing/).
444
-
-`apigw_rest`: for events coming from [Amazon API Gateway Rest APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html).
445
-
-`apigw_http`: for events coming from [Amazon API Gateway HTTP APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) and [AWS Lambda Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html).
446
-
-`apigw_websockets`: for events coming from [Amazon API Gateway WebSockets](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html).
447
-
448
-
If you only want to support one of these sources, you can disable the default features, and enable only the source that you care about in your package's `Cargo.toml` file. Substitute the dependency line for `lambda_http` for the snippet below, changing the feature that you want to enable:
449
-
450
-
```toml
451
-
[dependencies.lambda_http]
452
-
version = "0.5.3"
453
-
default-features = false
454
-
features = ["apigw_rest"]
455
-
```
456
-
457
-
This will make your function compile much faster.
458
-
459
353
## Supported Rust Versions (MSRV)
460
354
461
355
The AWS Lambda Rust Runtime requires a minimum of Rust 1.70, and is not guaranteed to build on compiler versions earlier than that.
When you integrate HTTP Lambda functions with API Gateway stages, the path received in the request will include the stage as the first segment, for example `/production/api/v1`, where `production` is the API Gateway stage.
236
236
237
237
If you don't want to receive the stage as part of the path, you can set the environment variable `AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH` to `true`, either in your Lambda function configuration, or inside the `main` Rust function. Following the previous example, when this environment variable is present, the path that the function receives is `/api/v1`, eliminating the stage from the first segment.
238
+
239
+
## Feature flags
240
+
241
+
`lambda_http` is a wrapper for HTTP events coming from three different services, Amazon Load Balancer (ALB), Amazon Api Gateway (APIGW), and AWS Lambda Function URLs. Amazon Api Gateway can also send events from three different endpoints, REST APIs, HTTP APIs, and WebSockets. `lambda_http` transforms events from all these sources into native `http::Request` objects, so you can incorporate Rust HTTP semantics into your Lambda functions.
242
+
243
+
By default, `lambda_http` compiles your function to support any of those services. This increases the compile time of your function because we have to generate code for all the sources. In reality, you'll usually put a Lambda function only behind one of those sources. You can choose which source to generate code for with feature flags.
244
+
245
+
The available features flags for `lambda_http` are the following:
246
+
247
+
-`alb`: for events coming from [Amazon Elastic Load Balancer](https://aws.amazon.com/elasticloadbalancing/).
248
+
-`apigw_rest`: for events coming from [Amazon API Gateway Rest APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html).
249
+
-`apigw_http`: for events coming from [Amazon API Gateway HTTP APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) and [AWS Lambda Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html).
250
+
-`apigw_websockets`: for events coming from [Amazon API Gateway WebSockets](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html).
251
+
252
+
If you only want to support one of these sources, you can disable the default features, and enable only the source that you care about in your package's `Cargo.toml` file. Substitute the dependency line for `lambda_http` for the snippet below, changing the feature that you want to enable:
0 commit comments