Skip to content

Commit 1e83d51

Browse files
committed
docs: add intro & getting started
1 parent b6f75b5 commit 1e83d51

File tree

10 files changed

+228
-32
lines changed

10 files changed

+228
-32
lines changed

Diff for: docs/contributing/conventions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ There are also a few other workspaces that are not utilities published to npm, b
3636

3737
* `examples/snippets`: contains the documentation code snippets
3838
* `examples/app`: contains an example project that can be deployed via AWS CDK or AWS SAM
39-
* `layers`: contains the code used to build and publish the [Lambda layers](../index.md#lambda-layer)
39+
* `layers`: contains the code used to build and publish the [Lambda layers](../getting-started/lambda-layers.md)
4040

4141
## Testing definition
4242

Diff for: docs/features/index.md

+75-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,78 @@ description: Features of Powertools for AWS Lambda
55

66
<!-- markdownlint-disable MD043 -->
77

8-
Stuff
8+
<div class="grid cards" markdown>
9+
10+
- __Tracer__
11+
12+
---
13+
14+
Instrument your code with minimal effort. Capture traces and metadata to understand the performance of your Lambda functions.
15+
16+
[:octicons-arrow-right-24: Read more](./tracer.md)
17+
18+
- __Logger__
19+
20+
---
21+
22+
JSON Structured logging made easier, key management, buffering, and Middy.js middleware to enrich structured logging with key Lambda context details.
23+
24+
[:octicons-arrow-right-24: Read more](./logger.md)
25+
26+
- __Metrics__
27+
28+
---
29+
30+
Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
31+
32+
[:octicons-arrow-right-24: Read more](./metrics.md)
33+
34+
- __Parameters__
35+
36+
---
37+
38+
High-level functions to retrieve one or more parameters from AWS SSM Parameter Store, AWS Secrets Manager, AWS AppConfig, and Amazon DynamoDB
39+
40+
[:octicons-arrow-right-24: Read more](./parameters.md)
41+
42+
- __Idempotency__
43+
44+
---
45+
46+
Class method decorator, Middy middleware, and function wrapper to make your Lambda functions idempotent and prevent duplicate execution based on payload content.
47+
48+
[:octicons-arrow-right-24: Read more](./idempotency.md)
49+
50+
- __Batch Processing__
51+
52+
---
53+
54+
Simplify the processing of batches of events with built-in support for SQS and DynamoDB Streams.
55+
56+
[:octicons-arrow-right-24: Read more](./batch.md)
57+
58+
- __JMESPath Functions__
59+
60+
---
61+
62+
Built-in JMESPath functions to easily deserialize common encoded JSON payloads in Lambda functions.
63+
64+
[:octicons-arrow-right-24: Read more](./jmespath.md)
65+
66+
- __Parser__
67+
68+
---
69+
70+
Utility to parse and validate AWS Lambda event payloads using Zod, a TypeScript-first schema declaration and validation library.
71+
72+
[:octicons-arrow-right-24: Read more](./parser.md)
73+
74+
- __Validation__
75+
76+
---
77+
78+
JSON Schema validation for events and responses, including JMESPath support to unwrap events before validation.
79+
80+
[:octicons-arrow-right-24: Read more](./validation.md)
81+
82+
</div>

Diff for: docs/getting-started/index.md

-8
This file was deleted.

Diff for: docs/getting-started/installation.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Installing Powertools for AWS Lambda
55

66
<!-- markdownlint-disable MD043 -->
77

8-
You can use Powertools for AWS Lambda (TypeScript) by installing it with your favorite dependency management, or via [Lambda Layers](lambda-layers.md).
8+
You can use Powertools for AWS Lambda (TypeScript) by installing it with your favorite dependency management, or via [Lambda Layers](./lambda-layers.md).
99

1010
The toolkit is compatible with both TypeScript and JavaScript code bases, and supports both CommonJS and ES modules.
1111

@@ -23,10 +23,10 @@ Some features use additional dependencies like the AWS SDK for JavaScript v3, wh
2323

2424
| Feature | Install | Default dependency |
2525
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------- |
26-
| **[Tracer](./features/tracer.md)** | **`npm i @aws-lambda-powertools/tracer`**{.copyMe}:clipboard: | `aws-xray-sdk-core` |
27-
| **[Idempotency](./features/idempotency.md)** | **`npm i @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb`**{.copyMe}:clipboard: | |
28-
| **[Parameters (SSM)](./features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-ssm`**{.copyMe}:clipboard: | |
29-
| **[Parameters (Secrets Manager)](./features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-secrets-manager`**{.copyMe}:clipboard: | |
30-
| **[Parameters (AppConfig)](./features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-appconfigdata`**{.copyMe}:clipboard: | |
31-
| **[Parser](./features/parser.md)** | **`npm i @aws-lambda-powertools/parser zod@~3`**{.copyMe}:clipboard: | |
32-
| **[Validation](./features/validation.md)** | **`npm i @aws-lambda-powertools/validation`**{.copyMe}:clipboard: | `ajv` |
26+
| **[Tracer](../features/tracer.md)** | **`npm i @aws-lambda-powertools/tracer`**{.copyMe}:clipboard: | `aws-xray-sdk-core` |
27+
| **[Idempotency](../features/idempotency.md)** | **`npm i @aws-lambda-powertools/idempotency @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb`**{.copyMe}:clipboard: | |
28+
| **[Parameters (SSM)](../features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-ssm`**{.copyMe}:clipboard: | |
29+
| **[Parameters (Secrets Manager)](../features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-secrets-manager`**{.copyMe}:clipboard: | |
30+
| **[Parameters (AppConfig)](../features/parameters.md)** | **`npm i @aws-lambda-powertools/parameters @aws-sdk/client-appconfigdata`**{.copyMe}:clipboard: | |
31+
| **[Parser](../features/parser.md)** | **`npm i @aws-lambda-powertools/parser zod@~3`**{.copyMe}:clipboard: | |
32+
| **[Validation](../features/validation.md)** | **`npm i @aws-lambda-powertools/validation`**{.copyMe}:clipboard: | `ajv` |

Diff for: docs/getting-started/lambda-layers.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ description: Using Powertools for AWS Lambda with Lambda layers
77

88
A [Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html){target="_blank"} is a `.zip` file archive that can contain additional code, pre-packaged dependencies, data, or configuration files. We provide a Lambda Layer for Powertools for AWS Lambda (TypeScript) to help you get started quickly with the library.
99

10-
You can add our layer both in the [AWS Lambda Console _(under `Layers`)_](https://eu-west-1.console.aws.amazon.com/lambda/home#/add/layer){target="_blank"}, or via your favorite infrastructure as code framework with the ARN value. You can use the Lambda Layer both with CommonJS and ESM (ECMAScript modules).
10+
You can add our layer both in the [AWS Lambda Console _(under `Layers`)_](https://docs.aws.amazon.com/lambda/latest/dg/adding-layers.html){target="_blank"}, or via your favorite infrastructure as code framework with the ARN value. You can use the Lambda Layer both with CommonJS and ESM (ECMAScript modules).
1111

1212
### Layer ARNs
1313

14+
We publish the Lambda Layer for Powertools for AWS Lambda (TypeScript) in all commercial regions and AWS GovCloud (US) regions.
15+
16+
???+ tip "Spotted a missing region?"
17+
18+
Open an [issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new?template=feature_request.yml&title=Feature%20request%3A%20missing%20Lambda%20layer%20region) in our GitHub repository to request it.
19+
1420
| Region | Layer ARN |
1521
| ---------------- | -------------------------------------------------------------------------------------------------------------------- |
1622
| `us-east-1` | [arn:aws:lambda:us-east-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:23](#){: .copyMe}:clipboard: |

Diff for: docs/getting-started/navigating-the-toolkit.md

+89-10
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,99 @@ description: Getting to know the Powertools for AWS Lambda Toolkit
55

66
<!-- markdownlint-disable MD043 -->
77

8-
## Instrumentation
8+
Powertools for AWS Lambda (TypeScript) is a collection of utilities designed to help you build serverless applications on AWS.
99

10-
Many of the utilities provided by Powertools for AWS Lambda (TypeScript) can be used with different programming paradigms:
10+
The toolkit is designed to be modular, so you can pick and choose the utilities you need for your application. Each utility is designed to be used independently, but they can also be used together to provide a complete solution for your serverless applications.
1111

12-
- **Middy** middleware. It is the best choice if your existing code base relies on the [Middy.js](https://middy.js.org/docs/) middleware engine. Powertools for AWS Lambda (TypeScript) offers compatible Middy middleware to make this integration seamless.
13-
- **Method decorator**. Use [TypeScript method decorators](https://www.typescriptlang.org/docs/handbook/decorators.html#method-decorators) if you prefer writing your business logic using [TypeScript Classes](https://www.typescriptlang.org/docs/handbook/classes.html). If you aren’t using Classes, this requires the most significant refactoring.
14-
- **Manually**. It provides the most granular control. It’s the most verbose approach, with the added benefit of no additional dependency and no refactoring to TypeScript Classes.
12+
## Patterns
1513

16-
The examples in this documentation will feature all the approaches described above wherever applicable.
14+
Many of the utilities provided can be used with different patterns, depending on your preferences and the structure of your code.
1715

18-
## Examples
16+
### Class Method Decorator
1917

20-
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){target="_blank"} directory. The application is a simple REST API that can be deployed via either AWS CDK or AWS SAM.
18+
If you prefer writing your business logic using Object-Oriented Programming (OOP) and TypeScript Classes, the Class Method decorator pattern is a good fit. This approach lets you decorate class methods with Powertools utilities, applying their functionality with minimal code changes.
2119

22-
If instead you want to see Powertools for AWS Lambda (TypeScript) in slightly different use cases, check the [Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo) or the [AWS Lambda performance tuning](https://github.com/aws-samples/optimizations-for-lambda-functions) repository.
20+
This pattern works well when you want to integrate Powertools for AWS Lambda (TypeScript) into an existing codebase without significant refactoring and with no additional runtime dependencies. Note that this approach relies on TypeScript's experimental decorator feature.
2321

24-
Both demos use Powertools for AWS Lambda (TypeScript) as well as demonstrating other common techniques for Lambda functions written in TypeScript.
22+
```ts
23+
import { Logger } from '@aws-lambda-powertools/logger';
24+
import { Tracer } from '@aws-lambda-powertools/tracer';
25+
import { Metrics } from '@aws-lambda-powertools/metrics';
26+
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
27+
import type { Context } from 'aws-lambda';
28+
29+
const logger = new Logger();
30+
const tracer = new Tracer();
31+
const metrics = new Metrics();
32+
33+
class Lambda implements LambdaInterface {
34+
@tracer.captureLambdaHandler()
35+
@logger.injectLambdaContext()
36+
@metrics.logMetrics()
37+
async handler(event: unknown, context: Context) {
38+
// Your business logic here
39+
}
40+
}
41+
const lambda = new Lambda();
42+
export const handler = lambda.handler.bind(lambda);
43+
```
44+
45+
### Middy.js Middleware
46+
47+
If your existing codebase relies on the [Middy.js](https://middy.js.org/docs/) middleware engine, you can use the Powertools for AWS Lambda (TypeScript) middleware to integrate with your existing code. This approach is similar to the Class Method decorator pattern but uses the Middy.js middleware engine to apply Powertools utilities.
48+
49+
```ts
50+
import { Logger } from '@aws-lambda-powertools/logger';
51+
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
52+
import { Tracer } from '@aws-lambda-powertools/tracer';
53+
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
54+
import { Metrics } from '@aws-lambda-powertools/metrics';
55+
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
56+
import middy from '@middy/core';
57+
58+
const logger = new Logger();
59+
const tracer = new Tracer();
60+
const metrics = new Metrics();
61+
62+
export const handler = middy()
63+
.use(captureLambdaHandler(tracer))
64+
.use(injectLambdaContext(logger))
65+
.use(logMetrics(metrics))
66+
.handler(async (event: unknown) => {
67+
// Your business logic here
68+
});
69+
```
70+
71+
### Functional Approach
72+
73+
If you prefer a more functional programming style, you can use the Powertools for AWS Lambda (TypeScript) utilities directly in your code without decorators or middleware. This approach is more verbose but provides the most control over how the utilities are applied.
74+
75+
```ts
76+
import { Logger } from '@aws-lambda-powertools/logger';
77+
import { Tracer } from '@aws-lambda-powertools/tracer';
78+
import { Metrics } from '@aws-lambda-powertools/metrics';
79+
import type { Context } from 'aws-lambda';
80+
81+
const logger = new Logger();
82+
const tracer = new Tracer();
83+
const metrics = new Metrics();
84+
85+
export const handler = async (event: unknown, context: Context) => {
86+
logger.addContext(context);
87+
logger.logEventIfEnabled(event);
88+
89+
const subsegment = tracer
90+
.getSegment()
91+
?.addNewSubsegment('#### handler');
92+
93+
try {
94+
// Your business logic here
95+
} catch (error) {
96+
logger.error('Error occurred', { error });
97+
tracer.addErrorAsMetadata(error);
98+
} finally {
99+
subsegment?.close();
100+
metrics.publishStoredMetrics();
101+
}
102+
};
103+
```

Diff for: docs/getting-started/typescript-settings.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,44 @@ description: Configuration settings for using Powertools with TypeScript
55

66
<!-- markdownlint-disable MD043 -->
77

8-
Stuff
8+
While you can use the toolkit with JavaScript, using TypeScript is recommended.
9+
10+
The toolkit is written in TypeScript, and the type definitions are included in the package. This means you can take advantage of TypeScript's static typing and other features when using it.
11+
12+
We officially support TypeScript 5.0 and later, and our development is done using the latest version of TypeScript. We recommend using the latest version of TypeScript to take advantage of the latest features and improvements.
13+
14+
## TypeScript Configuration
15+
16+
The toolkit should work with most TypeScript configurations. The only requirement is that `experimentalDecorators` is set to `true` if you are using class method decorators. This is because we only support the legacy decorator proposal for now. We will support the new decorator proposal in the next major version of Powertools for AWS Lambda (TypeScript).
17+
18+
If you are looking for a starting point, the following `tsconfig.json` file is a good place to start. It includes the recommended settings along with some modern TypeScript features.
19+
20+
```json
21+
{
22+
"compilerOptions": {
23+
"target": "ES2022",
24+
"module": "NodeNext",
25+
"moduleResolution": "NodeNext",
26+
"lib": [
27+
"es2022"
28+
],
29+
"declaration": true,
30+
"strict": true,
31+
"noImplicitAny": true,
32+
"strictNullChecks": true,
33+
"noImplicitThis": true,
34+
"alwaysStrict": true,
35+
"noUnusedLocals": false,
36+
"noUnusedParameters": false,
37+
"noImplicitReturns": true,
38+
"noFallthroughCasesInSwitch": false,
39+
"inlineSourceMap": true,
40+
"inlineSources": true,
41+
"experimentalDecorators": true,
42+
"strictPropertyInitialization": false
43+
},
44+
"exclude": [
45+
"node_modules"
46+
]
47+
}
48+
```

Diff for: docs/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ Powertools for AWS Lambda (TypeScript) is built as a modular toolkit, so you can
5252
| [Parser](./features/parser.md) | Utility to parse and validate AWS Lambda event payloads using Zod, a TypeScript-first schema declaration and validation library. |
5353
| [Validation](./features/validation.md) | JSON Schema validation for events and responses, including JMESPath support to unwrap events before validation. |
5454

55+
## Examples
56+
57+
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){target="_blank"} directory, which contains both code snippets for specific use cases, as well as a full example application.
58+
59+
If instead you want to see Powertools for AWS Lambda (TypeScript) in a more involved context, check the [Powertools for AWS workshop](https://github.com/aws-samples/powertools-for-aws-lambda-workshop/tree/main/functions/typescript) where we demonstrate how to use toolkit in a more complex application.
60+
5561
## Support Powertools for AWS
5662

5763
There are many ways you can help us gain future investments to improve everyone's experience:

Diff for: docs/upgrade.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ V2 is focused on official support for ESM (ECMAScript modules). We've made other
3232
Before you start, we suggest making a copy of your current working project or create a new git branch.
3333

3434
1. Upgrade Node.js to v18 or higher, Node.js v20 is recommended.
35-
2. Ensure that you have the latest Powertools for AWS Lambda (TypeScript) version via [Lambda Layer](./index.md#lambda-layer) or npm.
35+
2. Ensure that you have the latest Powertools for AWS Lambda (TypeScript) version via [Lambda Layer](./getting-started/lambda-layers.md) or npm.
3636
3. Review the following sections to confirm whether they apply to your codebase.
3737

3838
## ESM support

Diff for: mkdocs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ nav:
3333
- Homepage:
3434
- index.md
3535
- Getting Started:
36-
- getting-started/index.md
3736
- Navigating the toolkit: getting-started/navigating-the-toolkit.md
3837
- Installation: getting-started/installation.md
3938
- TypeScript settings: getting-started/typescript-settings.md

0 commit comments

Comments
 (0)