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
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).
128
128
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());
0 commit comments