Skip to content

Commit ebb9dd0

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents f5ae666 + f8b9a2a commit ebb9dd0

File tree

68 files changed

+829
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+829
-284
lines changed

.github/actions/rust-build/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ inputs:
77
toolchain:
88
required: true
99
description: "the Rust toolchain to use"
10+
run-tests:
11+
required: true
12+
default: true
13+
description: "whether to run tests in addition to building"
1014

1115
runs:
1216
using: "composite"
@@ -22,5 +26,6 @@ runs:
2226
run: cargo build --all-features --verbose --package ${{ inputs.package }}
2327

2428
- name: Run tests
29+
if: ${{ inputs.run-tests == 'true' }}
2530
shell: bash
2631
run: cargo test --all-features --verbose --package ${{ inputs.package }}

.github/workflows/build-events.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ jobs:
1616
strategy:
1717
matrix:
1818
toolchain:
19-
- "1.71.1" # Current MSRV
19+
- "1.81.0" # Current MSRV
2020
- stable
2121
env:
2222
RUST_BACKTRACE: 1
2323
steps:
2424
- uses: actions/checkout@v3
25-
2625
- name: Build events
2726
uses: ./.github/actions/rust-build
2827
with:
@@ -34,6 +33,23 @@ jobs:
3433
- uses: actions/checkout@v3
3534
- uses: dtolnay/rust-toolchain@stable
3635
- uses: Swatinem/rust-cache@v2
37-
3836
- name: Test individual event features
3937
run: make check-event-features
38+
semver:
39+
name: semver
40+
needs: [build, check-event-features]
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
- name: Check `aws_lambda_events` semver with only default features
45+
uses: obi1kenobi/cargo-semver-checks-action@v2
46+
with:
47+
rust-toolchain: stable
48+
package: aws_lambda_events
49+
feature-group: default-features
50+
- name: Check `aws_lambda_events` semver with all features
51+
uses: obi1kenobi/cargo-semver-checks-action@v2
52+
with:
53+
rust-toolchain: stable
54+
package: aws_lambda_events
55+
feature-group: all-features

.github/workflows/build-extension.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check Lambda Runtime
1+
name: Check Lambda Extension
22

33
on:
44
push:
@@ -22,22 +22,37 @@ jobs:
2222
strategy:
2323
matrix:
2424
toolchain:
25-
- "1.71.1" # Current MSRV
25+
- "1.81.0" # Current MSRV
2626
- stable
2727
env:
2828
RUST_BACKTRACE: 1
2929
steps:
3030
- uses: actions/checkout@v3
31-
3231
- name: Build Runtime API Client
3332
uses: ./.github/actions/rust-build
3433
with:
3534
package: lambda_runtime_api_client
3635
toolchain: ${{ matrix.toolchain}}
37-
38-
3936
- name: Build Extensions runtime
4037
uses: ./.github/actions/rust-build
4138
with:
4239
package: lambda-extension
4340
toolchain: ${{ matrix.toolchain}}
41+
semver:
42+
name: semver
43+
needs: build-runtime
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Check `lambda-extension` semver with only default features
48+
uses: obi1kenobi/cargo-semver-checks-action@v2
49+
with:
50+
rust-toolchain: stable
51+
package: lambda-extension
52+
feature-group: default-features
53+
- name: Check `lambda-extension` semver with all features
54+
uses: obi1kenobi/cargo-semver-checks-action@v2
55+
with:
56+
rust-toolchain: stable
57+
package: lambda-extension
58+
feature-group: all-features
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build integration tests
2+
3+
on:
4+
push:
5+
paths:
6+
- 'lambda-runtime-api-client/**'
7+
- 'lambda-runtime/**'
8+
- 'lambda-http/**'
9+
- 'lambda-extension/**'
10+
- 'Cargo.toml'
11+
12+
pull_request:
13+
paths:
14+
- 'lambda-runtime-api-client/**'
15+
- 'lambda-runtime/**'
16+
- 'lambda-http/**'
17+
- 'lambda-extension/**'
18+
- 'Cargo.toml'
19+
20+
jobs:
21+
build-runtime:
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
toolchain:
26+
- "1.81.0" # Current MSRV
27+
- stable
28+
env:
29+
RUST_BACKTRACE: 1
30+
steps:
31+
- uses: actions/checkout@v3
32+
33+
- name: Build Integration tests
34+
uses: ./.github/actions/rust-build
35+
with:
36+
package: lambda-integration-tests
37+
toolchain: ${{ matrix.toolchain}}
38+
# the tests will generally fail in ci since they make a network call to a real endpoint,
39+
# this step is just designed to make sure they build successfully
40+
run-tests: false

.github/workflows/build-runtime.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,42 @@ jobs:
2121
strategy:
2222
matrix:
2323
toolchain:
24-
- "1.71.1" # Current MSRV
24+
- "1.81.0" # Current MSRV
2525
- stable
2626
env:
2727
RUST_BACKTRACE: 1
2828
steps:
2929
- uses: actions/checkout@v3
30-
3130
- name: Build Runtime API Client
3231
uses: ./.github/actions/rust-build
3332
with:
3433
package: lambda_runtime_api_client
3534
toolchain: ${{ matrix.toolchain}}
36-
3735
- name: Build Functions runtime
3836
uses: ./.github/actions/rust-build
3937
with:
4038
package: lambda_runtime
4139
toolchain: ${{ matrix.toolchain}}
42-
4340
- name: Build HTTP layer
4441
uses: ./.github/actions/rust-build
4542
with:
4643
package: lambda_http
4744
toolchain: ${{ matrix.toolchain}}
45+
semver:
46+
name: semver
47+
needs: build-runtime
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- name: Check `lambda_runtime_api_client`, `lambda_runtime`, lambda_http` semver with only default features
52+
uses: obi1kenobi/cargo-semver-checks-action@v2
53+
with:
54+
rust-toolchain: stable
55+
package: lambda_runtime_api_client, lambda_runtime, lambda_http
56+
feature-group: default-features
57+
- name: Check `lambda_runtime_api_client`, `lambda_runtime`, lambda_http` semver with all features
58+
uses: obi1kenobi/cargo-semver-checks-action@v2
59+
with:
60+
rust-toolchain: stable
61+
package: lambda_runtime_api_client, lambda_runtime, lambda_http
62+
feature-group: all-features

.github/workflows/check-docs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Check rustdocs
2+
# this is its own workflow since we to to use unstable
3+
# to have the docs.rs display of feature flags
4+
5+
on:
6+
push:
7+
paths:
8+
- 'lambda-runtime/**'
9+
- 'lambda-runtime-api-client/**'
10+
- 'lambda-http/**'
11+
- 'lambda-events/**'
12+
- 'lambda-extension/**'
13+
- 'Cargo.toml'
14+
15+
pull_request:
16+
paths:
17+
- 'lambda-runtime/**'
18+
- 'lambda-runtime-api-client/**'
19+
- 'lambda-http/**'
20+
- 'lambda-events/**'
21+
- 'lambda-extension/**'
22+
- 'Cargo.toml'
23+
24+
jobs:
25+
build-runtime:
26+
runs-on: ubuntu-latest
27+
28+
env:
29+
RUST_BACKTRACE: 1
30+
steps:
31+
- uses: actions/checkout@v3
32+
- uses: dtolnay/rust-toolchain@nightly
33+
34+
- name: Check documentation
35+
shell: bash
36+
env:
37+
RUSTFLAGS: --cfg docsrs
38+
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
39+
run: cargo doc --no-deps --document-private-items --all-features

.github/workflows/run-integration-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ jobs:
1818
repo: cargo-lambda/cargo-lambda
1919
platform: linux
2020
arch: x86_64
21+
# TODO: unpin once https://github.com/awslabs/aws-lambda-rust-runtime/issues/1006 is fixed
22+
tag: v1.8.1
2123
- name: install Zig toolchain
22-
uses: korandoru/setup-zig@v1
24+
uses: mlugg/setup-zig@v2
2325
with:
24-
zig-version: 0.10.0
26+
version: 0.10.0
2527
- name: install SAM
2628
uses: aws-actions/setup-sam@v2
2729
with:

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Rust Runtime for AWS Lambda
22

3-
[![Build Status](https://github.com/awslabs/aws-lambda-rust-runtime/workflows/Rust/badge.svg)](https://github.com/awslabs/aws-lambda-rust-runtime/actions)
3+
[![Build Status](https://github.com/awslabs/aws-lambda-rust-runtime/actions/workflows/check-examples.yml/badge.svg)](https://github.com/awslabs/aws-lambda-rust-runtime/actions)
44

55
This package makes it easy to run AWS Lambda Functions written in Rust. This workspace includes multiple crates:
66

@@ -82,7 +82,7 @@ when a function invocation fails, AWS Lambda expects you to return an object tha
8282
}
8383
```
8484

85-
The Rust Runtime for Lambda uses a struct called `Diagnostic` to represent function errors internally. The runtime implements the converstion of several general errors types, like `std::error::Error`, into `Diagnostic`. For these general implementations, the `error_type` is the name of the value type returned by your function. For example, if your function returns `lambda_runtime::Error`, the `error_type` will be something like `alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>`, which is not very descriptive.
85+
The Rust Runtime for Lambda uses a struct called `Diagnostic` to represent function errors internally. The runtime implements the conversion of several general error types, like `std::error::Error`, into `Diagnostic`. For these general implementations, the `error_type` is the name of the value type returned by your function. For example, if your function returns `lambda_runtime::Error`, the `error_type` will be something like `alloc::boxed::Box<dyn core::error::Error + core::marker::Send + core::marker::Sync>`, which is not very descriptive.
8686

8787
### Implement your own Diagnostic
8888

@@ -126,6 +126,52 @@ async fn handler(_event: LambdaEvent<Request>) -> Result<(), Diagnostic> {
126126

127127
You can see more examples on how to use these error crates in our [example repository](https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/examples/basic-error-error-crates-integration).
128128

129+
### Graceful shutdown
130+
131+
`lambda_runtime` offers a helper to simplify configuring graceful shutdown signal handling, `spawn_graceful_shutdown_handler()`. This requires the `graceful-shutdown` feature flag and only supports Unix systems.
132+
133+
You can use it by passing a `FnOnce` closure that returns an async block. That async block will be executed
134+
when the function receives a `SIGTERM` or `SIGKILL`.
135+
136+
Note that this helper is opinionated in a number of ways. Most notably:
137+
1. It spawns a task to drive your signal handlers
138+
2. It registers a 'no-op' extension in order to enable graceful shutdown signals
139+
3. It panics on unrecoverable errors
140+
141+
If you prefer to fine-tune the behavior, refer to the implementation of `spawn_graceful_shutdown_handler()` as a starting point for your own.
142+
143+
For more information on graceful shutdown handling in AWS Lambda, see: [aws-samples/graceful-shutdown-with-aws-lambda](https://github.com/aws-samples/graceful-shutdown-with-aws-lambda).
144+
145+
Complete example (cleaning up a non-blocking tracing writer):
146+
147+
```rust,no_run
148+
use lambda_runtime::{service_fn, LambdaEvent, Error};
149+
use serde_json::{json, Value};
150+
151+
#[tokio::main]
152+
async fn main() -> Result<(), Error> {
153+
let func = service_fn(func);
154+
155+
let (writer, log_guard) = tracing_appender::non_blocking(std::io::stdout());
156+
lambda_runtime::tracing::init_default_subscriber_with_writer(writer);
157+
158+
let shutdown_hook = || async move {
159+
std::mem::drop(log_guard);
160+
};
161+
lambda_runtime::spawn_graceful_shutdown_handler(shutdown_hook).await;
162+
163+
lambda_runtime::run(func).await?;
164+
Ok(())
165+
}
166+
167+
async fn func(event: LambdaEvent<Value>) -> Result<Value, Error> {
168+
let (event, _context) = event.into_parts();
169+
let first_name = event["firstName"].as_str().unwrap_or("world");
170+
171+
Ok(json!({ "message": format!("Hello, {}!", first_name) }))
172+
}
173+
```
174+
129175
## Building and deploying your Lambda functions
130176

131177
If you already have Cargo Lambda installed in your machine, run the next command to build your function:
@@ -409,7 +455,7 @@ fn main() -> Result<(), Box<Error>> {
409455

410456
## Supported Rust Versions (MSRV)
411457

412-
The AWS Lambda Rust Runtime requires a minimum of Rust 1.71.1, and is not guaranteed to build on compiler versions earlier than that.
458+
The AWS Lambda Rust Runtime requires a minimum of Rust 1.81.0, and is not guaranteed to build on compiler versions earlier than that.
413459

414460
## Security
415461

0 commit comments

Comments
 (0)