Skip to content

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 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.

Tenets

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.

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 for TypeScript utilities (which from here will be referred as Powertools) 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 passed in constructors or in middleware/decorators 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_TRACER_CAPTURE_HTTPS_REQUESTS Captures HTTP(s) requests as segments. Tracer true
POWERTOOLS_LOGGER_LOG_EVENT Logs incoming event Logger false
POWERTOOLS_LOGGER_SAMPLE_RATE Debug log sampling Logger 0
POWERTOOLS_LOGGER_LOG_EVENT Logs incoming events Logger false
LOG_LEVEL Sets logging level Logger INFO

Examples

Credits

Connect


Last update: 2022-06-23