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: packages/commons/README.md
+82-63
Original file line number
Diff line number
Diff line change
@@ -4,73 +4,96 @@ Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serve
4
4
5
5
You can use the library in both TypeScript and JavaScript code bases.
6
6
7
-
> Also available in [Python](https://github.com/aws-powertools/powertools-lambda-python), [Java](https://github.com/aws-powertools/powertools-lambda-java), and [.NET](https://github.com/aws-powertools/powertools-lambda-dotnet).
The Commons package contains a set of utilities that are shared across one or more Powertools for AWS Lambda (TypeScript) utilities. Some of these utilities can also be used independently in your AWS Lambda functions.
10
10
11
-
## Table of contents <!--- omit in toc -->
11
+
## Usage
12
12
13
-
-[Table of contents ](#table-of-contents-)
14
-
-[Features](#features)
15
-
-[Getting started](#getting-started)
16
-
-[Installation](#installation)
17
-
-[Examples](#examples)
18
-
-[Demo applications](#demo-applications)
19
-
-[Contribute](#contribute)
20
-
-[Roadmap](#roadmap)
21
-
-[Connect](#connect)
22
-
-[How to support Powertools for AWS Lambda (TypeScript)?](#how-to-support-powertools-for-aws-lambda-typescript)
23
-
-[Becoming a reference customer](#becoming-a-reference-customer)
24
-
-[Sharing your work](#sharing-your-work)
25
-
-[Using Lambda Layer](#using-lambda-layer)
26
-
-[Credits](#credits)
27
-
-[License](#license)
13
+
To get started, install the utility by running:
28
14
29
-
## Features
30
-
31
-
***[Tracer](https://docs.powertools.aws.dev/lambda/typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
32
-
***[Logger](https://docs.powertools.aws.dev/lambda/typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
33
-
***[Metrics](https://docs.powertools.aws.dev/lambda/typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
34
-
***[Parameters](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/)** - High-level functions to retrieve one or more parameters from AWS SSM, Secrets Manager, AppConfig, and DynamoDB
35
-
***[Idempotency](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/)** - Class method decorator, Middy middleware, and function wrapper to make your Lambda functions idempotent and prevent duplicate execution based on payload content
36
-
***[Batch processing](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/batch/)** - Utility to handle partial failures when processing batches from Amazon SQS, Amazon Kinesis Data Streams, and Amazon DynamoDB Streams.
15
+
```sh
16
+
npm i @aws-lambda-powertools/commons
17
+
```
37
18
38
-
##Getting started
19
+
### Type utils
39
20
40
-
Find the complete project's [documentation here](https://docs.powertools.aws.dev/lambda/typescript).
21
+
When working with different objects and values, you may want to do runtime type checks. The utility comes with a set of type utilities that you can use to check the type of an object or value.
The Powertools for AWS Lambda (TypeScript) utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).
45
28
46
-
Each TypeScript utility is installed as standalone npm package.
29
+
const value = { key: 'value' };
30
+
if (isRecord(value)) {
31
+
// value is a record
32
+
}
47
33
48
-
Install all three core utilities at once with this single command:
👉 [Installation guide for the **Parameters**utility](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/#getting-started)
74
+
In some cases, you may want to define a type for a JSON object or value. The utility comes with a set of types that you can use to define your JSON objects.
You can find examples of how to use Powertools for AWS Lambda (TypeScript) in the [examples](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/app) directory. The application is a simple REST API that can be deployed via either AWS CDK or AWS SAM.
80
+
### Lambda interface
67
81
68
-
### Demo applications
82
+
When using object-oriented patterns to define your Lambda handlers, you can use the `LambdaHandler` interface to define the shape of your handler methods.
69
83
70
-
The [Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo) shows how to use Powertools for AWS Lambda (TypeScript).
71
-
You can find instructions on how to deploy and load test this application in the [repository](https://github.com/aws-samples/serverless-typescript-demo).
The [AWS Lambda performance tuning](https://github.com/aws-samples/optimizations-for-lambda-functions) repository also uses Powertools for AWS Lambda (TypeScript) as well as demonstrating other performance tuning techniques for Lambda functions written in TypeScript.
88
+
classLambdaimplementsLambdaInterface {
89
+
public handler =async (event:unknown, context:Context) => {
90
+
// Your handler code here
91
+
}
92
+
}
93
+
94
+
const handlerClass =newLambda();
95
+
exportconst handler =lambda.handler.bind(lambda);
96
+
```
74
97
75
98
## Contribute
76
99
@@ -83,8 +106,8 @@ Help us prioritize upcoming functionalities or utilities by [upvoting existing R
83
106
84
107
## Connect
85
108
86
-
***Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (TypeScript) [here](https://docs.powertools.aws.dev/lambda/typescript/latest/we_made_this).
112
135
113
136
### Using Lambda Layer
114
137
115
-
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](#lambda-layers), you can add Powertools for AWS Lambda (TypeScript) as a dev dependency (or as part of your virtual env) to not impact the development process.
116
-
117
-
## Credits
118
-
119
-
Credits for the Lambda Powertools for AWS Lambda (TypeScript) idea go to [DAZN](https://github.com/getndazn) and their [DAZN Lambda Powertools](https://github.com/getndazn/dazn-lambda-powertools/).
138
+
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency to not impact the development process.
Copy file name to clipboardExpand all lines: packages/commons/src/Utility.ts
+39-13
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,11 @@
1
1
/**
2
-
* ## Intro
3
-
* Utility is a base class that other Powertools for AWS Lambda (TypeScript) utilites can extend to inherit shared logic.
2
+
* `Utility` is a base class that other Powertools for AWS Lambda (TypeScript) utilites can extend to inherit shared logic.
4
3
*
4
+
* Its main purpose is to encapsulate the cold start heuristic logic. Cold start is a term commonly used to describe the `Init` phase of a Lambda function.
5
+
* In this phase, Lambda creates or unfreezes an execution environment with the configured resources, downloads the code for the function and all layers,
6
+
* initializes any extensions, initializes the runtime, and then runs the function’s initialization code (the code outside the main handler).
5
7
*
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.
8
+
* The Init phase happens either during the first invocation, or in advance of function invocations if you have enabled provisioned concurrency.
14
9
*
15
10
* 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
11
*
@@ -21,7 +16,7 @@
21
16
*
22
17
* If you want to use this logic in your own utilities, `Utility` provides two methods:
23
18
*
24
-
* #### `getColdStart()`
19
+
* `Utility.getColdStart()`
25
20
*
26
21
* 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
22
*
@@ -36,7 +31,7 @@
36
31
* };
37
32
* ```
38
33
*
39
-
* #### `isColdStart()`
34
+
* `Utility.isColdStart()`
40
35
*
41
36
* This method is an alias of `getColdStart()` and is exposed for convenience and better readability in certain usages.
0 commit comments