| [ Web Proxy ] |
| Viewing: https://docs.powertools.aws.dev/lambda/python/latest/#lambda-layer | [Back] [Original] |
Powertools for AWS Lambda (Python) is a developer toolkit to implement Serverless best practices and increase developer velocity.
Ready to use Powertools for AWS Lambda? Jump to Installation.
Features
Adopt one, a few, or all industry practices. Progressively.
Installation
Install via pip, Lambda Layers, or SAR.
[] Support this project
Become a public reference, share your work, join the community.
Other languages
Powertools is also available in other languages.
| Utility | Description |
|---|---|
| Tracer | Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions |
| Logger | Structured logging made easier, and target to enrich structured logging with key Lambda context details |
| Metrics | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF) |
| Event Handler | Event handler for API Gateway, ALB, Lambda Function URL, VPC Lattice, AppSync, and Bedrock Agents |
| Parameters | Retrieve and cache parameter values from Parameter Store, Secrets Manager, AppConfig, or DynamoDB |
| Parser | Data parsing and deep validation using Pydantic |
| Batch Processing | Handle partial failures for SQS, Kinesis Data Streams, and DynamoDB Streams |
| Idempotency | Make your Lambda functions idempotent and prevent duplicate execution |
| Feature Flags | A simple rule engine to evaluate when features should be enabled |
| Validation | JSON Schema validator for inbound events and responses |
| Data Masking | Protect confidential data with easy removal or encryption |
| Streaming | Stream datasets larger than available memory |
| Middleware Factory | Create your own middleware to run logic before and after each Lambda invocation |
| Typing | Static typing classes to speedup development in your IDE |
| Event Source Data Classes | Data classes describing the schema of common Lambda event triggers |
| JMESPath Functions | Built-in JMESPath functions to deserialize common encoded JSON payloads |
| Kafka | Deserialize and validate Kafka events with support for Avro, Protocol Buffers, and JSON Schema |
You can find examples in the examples directory and a quick start using SAM CLI:
1 | |
For a more complete example, check the Powertools for AWS workshop.
Explicit parameters take precedence over environment variables.
| Environment variable | Description | Utility | Default |
|---|---|---|---|
POWERTOOLS_SERVICE_NAME |
Service name for tracing, metrics, and logging | All | service_undefined |
POWERTOOLS_LOG_LEVEL |
Sets logging level | Logger | INFO |
POWERTOOLS_LOGGER_LOG_EVENT |
Logs incoming event | Logger | false |
POWERTOOLS_LOGGER_SAMPLE_RATE |
Debug log sampling | Logger | 0 |
POWERTOOLS_METRICS_NAMESPACE |
Namespace for metrics | Metrics | None |
POWERTOOLS_METRICS_DISABLED |
Disables metrics emission | Metrics | false |
POWERTOOLS_TRACE_DISABLED |
Disables tracing | Tracer | false |
POWERTOOLS_TRACER_CAPTURE_RESPONSE |
Captures return as metadata | Tracer | true |
POWERTOOLS_TRACER_CAPTURE_ERROR |
Captures exception as metadata | Tracer | true |
POWERTOOLS_PARAMETERS_MAX_AGE |
Cache TTL in seconds | Parameters | 5 |
POWERTOOLS_PARAMETERS_SSM_DECRYPT |
Decrypt SSM parameters | Parameters | false |
POWERTOOLS_DEV |
Increases verbosity for development | Multiple | false |
POWERTOOLS_DEBUG |
Enables debug logging for Powertools | All | false |
When POWERTOOLS_DEV is set to true, it enables development-friendly settings:
| Utility | Effect |
|---|---|
| Logger | Increases JSON indentation to 4 for readability |
| Event Handler | Enables full traceback errors and CORS in dev mode |
| Tracer | Disables tracing in non-Lambda environments |
| Metrics | Disables metrics emission (can be overridden) |
[] Become a public reference
Add your company name and logo on our landing page.
[] Share your work
Blog posts, videos, and sample projects about Powertools.
[] Join the community
Connect, ask questions, and share what features you use.
These are our core principles to guide our decision making.
| Web Proxy Viewer | New URL | Original Page |