Skip to content

Commit

Permalink
docs: added usage section
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Feb 28, 2022
1 parent c7954b5 commit e808c75
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
22 changes: 18 additions & 4 deletions docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/logger
```

### Usage

The `Logger` utility should always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition to this, `Logger` can also be aware of things like whether or not a given invocation had a cold start or not and inject the appropriate fields into the log.

=== "handler.ts"

```typescript hl_lines="1 3"
import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

The library requires two settings. You can set them as environment variables, or pass them in the constructor.
Expand All @@ -44,8 +60,6 @@ For a **complete list** of supported environment variables, refer to [this secti

#### Example using AWS Serverless Application Model (SAM)

The `Logger` utility is instantiated outside of the Lambda handler. In doing this, the same instance can be used across multiple invocations inside the same execution environment. This allows `Metrics` to be aware of things like whether or not a given invocation had a cold start or not.

=== "handler.ts"

```typescript hl_lines="1 4"
Expand All @@ -56,8 +70,8 @@ The `Logger` utility is instantiated outside of the Lambda handler. In doing thi

// You can also pass the parameters in the constructor
// const logger = new Logger({
// logLevel: "WARN",
// serviceName: "serverlessAirline"
// logLevel: 'WARN',
// serviceName: 'serverlessAirline'
// });
```

Expand Down
16 changes: 16 additions & 0 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/metrics
```

### Usage

The `Metrics` utility should always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition to this, `Metrics` can also be aware of things like whether or not a given invocation had a cold start or not and emit the appropriate metrics.

=== "handler.ts"

```typescript hl_lines="1 3"
import { Metrics } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

The library requires two settings. You can set them as environment variables, or pass them in the constructor.
Expand Down
16 changes: 16 additions & 0 deletions docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/tracer
```

### Usage

The `Tracer` utility should always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition to this, `Tracer` can also be aware of things like whether or not a given invocation had a cold start or not and annotate your traces accordingly.

=== "handler.ts"

```typescript hl_lines="1 3"
import { Tracer } from '@aws-lambda-powertools/tracer';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

The library has one optional setting. You can set it as environment variable, or pass it in the constructor.
Expand Down

0 comments on commit e808c75

Please sign in to comment.