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
* Utility is a base class that other Powertools utilites can extend to inherit shared logic.
4
+
*
5
+
*
6
+
* ## Key features
7
+
* * Cold Start heuristic to determine if the current
8
+
*
9
+
* ## Usage
10
+
*
11
+
* ### Cold Start
12
+
*
13
+
* Cold start is a term commonly used to describe the `Init` phase of a Lambda function. In this phase, Lambda creates or unfreezes an execution environment with the configured resources, downloads the code for the function and all layers, initializes any extensions, initializes the runtime, and then runs the function’s initialization code (the code outside the main handler). The Init phase happens either during the first invocation, or in advance of function invocations if you have enabled provisioned concurrency.
14
+
*
15
+
* To learn more about the Lambda execution environment lifecycle, see the [Execution environment section](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html) of the AWS Lambda documentation.
16
+
*
17
+
* As a Powertools user you probably won't be using this class directly, in fact if you use other Powertools utilities the cold start heuristic found here is already used to:
18
+
* * Add a `coldStart` key to the structured logs when injecting context information in `Logger`
19
+
* * Emit a metric during a cold start function invocation in `Metrics`
20
+
* * Annotate the invocation segment with a `coldStart` key in `Tracer`
21
+
*
22
+
* If you want to use this logic in your own utilities, `Utility` provides two methods:
23
+
*
24
+
* #### `getColdStart()`
25
+
*
26
+
* Since the `Utility` class is instantiated outside of the Lambda handler it will persist across invocations of the same execution environment. This means that if you call `getColdStart()` multiple times, it will return `true` during the first invocation, and `false` afterwards.
27
+
*
28
+
* @example
29
+
* ```typescript
30
+
* import { Utility } from '@aws-lambda-powertools/commons';
0 commit comments