AWS Lambda Powertools for 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.
Core utilities such as Tracer, Logger, Metrics, and Event Handler will be available across all Lambda Powertools runtimes. Additional utilities are subjective to each language ecosystem and customer demand.
- 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.
|Tracer||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)|
Install all three core utilities at once with this single command:
Or refer to the installation guide of each utility:
You can instrument your code with Powertools in three different ways:
- Middy middleware. It is the best choice if your existing code base relies on the Middy middleware engine. Powertools offers compatible Middy middleware to make this integration seamless.
- Method decorator. Use TypeScript method decorators if you prefer writing your business logic using TypeScript Classes. If you aren’t using Classes, this requires the most significant refactoring.
- 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.
The examples in this documentation will feature all the approaches described above, when applicable.
Explicit parameters passed in constructors or in middleware/decorators take precedence over environment variables.
|POWERTOOLS_SERVICE_NAME||Sets service name used for tracing namespace, metrics dimension and structured logging||All||
|POWERTOOLS_METRICS_NAMESPACE||Sets namespace used for metrics||Metrics||
|POWERTOOLS_TRACE_ENABLED||Explicitly disables tracing||Tracer||
|POWERTOOLS_TRACER_CAPTURE_RESPONSE||Captures Lambda or method return as metadata.||Tracer||
|POWERTOOLS_TRACER_CAPTURE_ERROR||Captures Lambda or method exception as metadata.||Tracer||
|POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS||Captures HTTP(s) requests as segments.||Tracer||
|POWERTOOLS_LOGGER_LOG_EVENT||Logs incoming event||Logger||
|POWERTOOLS_LOGGER_SAMPLE_RATE||Debug log sampling||Logger||
|LOG_LEVEL||Sets logging level||Logger||
Serverless TypeScript demo application¶
If you are interested in contributing to this project, please refer to our Contributing Guidelines.
The roadmap of Powertools is driven by customers’ demand.
Help us prioritize upcoming functionalities or utilities by upvoting existing RFCs and feature requests, or creating new ones, in this GitHub repository.
- AWS Developers Slack:
#lambda-powertools- Invite, if you don't have an account
- Email: firstname.lastname@example.org
This library is licensed under the MIT-0 License. See the LICENSE file.