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
Copy file name to clipboardExpand all lines: rust-demo/README.md
+28-4Lines changed: 28 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,20 @@
1
1
# rust graceful shutdown demo
2
2
3
-
This folder contains a simple rust function with [CloudWatch Lambda Insight](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-insights.html) enabled. CloudWatch Lambda Insight is
3
+
## Generating graceful shutdown signals
4
+
5
+
In order for Lambda to support graceful shutdown, at least one extension must be registered for your function.
6
+
This folder contains two examples demonstrating this. One uses an external extension, and one uses an internal extension.
7
+
8
+
For more information on the difference between the two, see [these Lambda Extensions API docs](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html).
9
+
10
+
### External extension
11
+
12
+
An external extension runs as a separate process alongside your function's process. This can be easier to reason about and keep your code simpler,
13
+
though it might add additional overhead if you don't actually need an external extension.
14
+
15
+
The external extension example assumes that the [CloudWatch Lambda Insight](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-insights.html) is enabled. CloudWatch Lambda Insight is a
4
16
monitoring and troubleshooting solution for serverless application. Its agent is an external extension. Any external
5
-
extension will work. We use Lambda Insight extension simply because it is readily available.
17
+
extension will work. We use Lambda Insight extension simply because it is readily available and useful. Note that this may incurs additional billing fees.
6
18
7
19
*It is recommended to use the latest [Lambda Insights extension](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html)*
8
20
```yaml
@@ -14,6 +26,15 @@ extension will work. We use Lambda Insight extension simply because it is readil
14
26
- CloudWatchLambdaInsightsExecutionRolePolicy
15
27
```
16
28
29
+
### Internal extension
30
+
31
+
Alternately, you can register an extension directly from within your Rust process. This adds code complexity but is somewhat lighter weight.
32
+
33
+
In our case, we use a dummy no-op extension that simply ignores any event that it receives. You can also use an internal extension that has
34
+
useful functionality - for instance, see this example of an internal extension that flushes telemetry: [ref](https://github.com/awslabs/aws-lambda-rust-runtime/blob/main/examples/extension-internal-flush).
35
+
36
+
## Signal handling in the function
37
+
17
38
In the function, a simple signal handler is added. It will be executed when the lambda runtime receives
18
39
a `SIGTERM`、`SIGINT` signal. You can also add more signal types yourself.
19
40
@@ -40,7 +61,10 @@ tokio::spawn(async move {
40
61
}
41
62
});
42
63
```
43
-
Use the following AWS SAM CLI commands to build and deploy this demo.
64
+
65
+
## Deploy and Test
66
+
67
+
Use the following AWS SAM CLI commands from within one of the two examples' subdirectories to build and deploy this demo.
0 commit comments