Homepage
Do not use this library in production
AWS Lambda Powertools for TypeScript is currently released as a beta developer preview and is intended strictly for feedback purposes only.
This version is not stable, and significant breaking changes might incur as part of the upcoming production-ready release.
Do not use this library for production workloads.
AWS Lambda Powertools TypeScript provides a suite of utilities for AWS Lambda functions running on the Node.js runtime, to ease the adoption of best practices such as tracing, structured logging, custom metrics, and more.
Tenets¶
This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes.
- AWS Lambda only. We optimise for AWS Lambda function environments and supported runtimes only. Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported.
- Eases the adoption of best practices. The main priority of the utilities is to facilitate best practices adoption, as defined in the AWS Well-Architected Serverless Lens; all other functionality is optional.
- Keep it lean. Additional dependencies are carefully considered for security and ease of maintenance, and prevent negatively impacting startup time.
- We strive for backwards compatibility. New features and changes should keep backwards compatibility. If a breaking change cannot be avoided, the deprecation and migration process should be clearly defined.
- We work backwards from the community. We aim to strike a balance of what would work best for 80% of customers. Emerging practices are considered and discussed via Requests for Comment (RFCs)
- Progressive. Utilities are designed to be incrementally adoptable for customers at any stage of their Serverless journey. They follow language idioms and their community’s common practices.
Features¶
Utility | Description |
---|---|
Tracer | Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions |
Logger | Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context |
Metrics | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) |
Installation¶
The AWS Lambda Powertools TypeScript utilities follow a modular approach, similar to the official AWS SDK v3 for JavaScript. Each TypeScript utility is installed as standalone NPM package.
Installation guide for the Tracer utility
Installation guide for the Logger utility
Installation guide for the Metrics utility
Environment variables¶
Info
Explicit parameters take precedence over environment variables.
Environment variable | Description | Utility | Default |
---|---|---|---|
POWERTOOLS_SERVICE_NAME | Sets service name used for tracing namespace, metrics dimension and structured logging | All | "service_undefined" |
POWERTOOLS_METRICS_NAMESPACE | Sets namespace used for metrics | Metrics | None |
POWERTOOLS_TRACE_ENABLED | Explicitly disables tracing | Tracer | true |
POWERTOOLS_TRACER_CAPTURE_RESPONSE | Captures Lambda or method return as metadata. | Tracer | true |
POWERTOOLS_TRACER_CAPTURE_ERROR | Captures Lambda or method exception as metadata. | Tracer | true |
POWERTOOLS_LOGGER_LOG_EVENT | Logs incoming event | Logger | false |
POWERTOOLS_LOGGER_SAMPLE_RATE | Debug log sampling | Logger | 0 |
POWERTOOLS_LOG_DEDUPLICATION_DISABLED | Disables log deduplication filter protection to use Pytest Live Log feature | Logger | false |
LOG_LEVEL | Sets logging level | Logger | INFO |
Examples¶
Credits¶
- Credits for the Lambda Powertools idea go to DAZN and their DAZN Lambda Powertools.
Connect¶
- AWS Developers Slack:
#lambda-powertools
- Invite, if you don't have an account** - Email: aws-lambda-powertools-feedback@amazon.com