github aws-powertools/powertools-lambda-python v3.25.0

5 hours ago

Summary

This release introduces per-route validation support in event handler, durable context support for logger and metric decorators, multiple dimension sets in metrics, S3 IntelligentTiering event support, and a URL-decode flag for ALB query parameters. We also shipped several important bug fixes across logger, parameters, event handler, and typing.

A huge thanks to @oyiz-michael, @chriselion, @maxrabin, @facu-01, and @Iamrodos, for their contributions πŸš€πŸŒŸ

Per-route validation support

Docs

You can now enable or disable validation on individual routes. This is useful when migrating incrementally - enable validation globally and opt-out specific legacy routes, or vice versa.

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from pydantic import BaseModel

app = APIGatewayRestResolver(enable_validation=True)

class Todo(BaseModel):
    title: str
    completed: bool

# This route has validation enabled (inherits from resolver)
@app.post("/todos")
def create_todo(todo: Todo) -> dict:
    return {"title": todo.title}

# This route opts out of validation
@app.get("/legacy", enable_validation=False)
def legacy_endpoint():
    return {"message": "no validation here"}

Durable Context support in Logger and Metrics decorators

Docs

Logger and Metrics decorators now handle AWS Lambda Durable Context automatically. When a durable function replays, the decorators unwrap the DurableContext to access the underlying Lambda context - no changes needed in your code.

from aws_lambda_powertools import Logger, Metrics
from aws_lambda_powertools.metrics import MetricUnit

logger = Logger()
metrics = Metrics()

@logger.inject_lambda_context  # automatically handles DurableContext
@metrics.log_metrics            # automatically handles DurableContext
def lambda_handler(event, context):
    logger.info("Processing event")
    metrics.add_metric(name="InvocationCount", unit=MetricUnit.Count, value=1)
    return {"statusCode": 200}

Multiple dimension sets in Metrics

Docs

You can now publish metrics with multiple dimension sets using add_dimensions(). Each call creates a new dimension set in the CloudWatch EMF output.

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit

metrics = Metrics()

@metrics.log_metrics
def lambda_handler(event, context):
    metrics.add_metric(name="OrderCount", unit=MetricUnit.Count, value=1)

    # Each call creates a separate dimension set
    metrics.add_dimensions(environment="prod", region="us-east-1")
    metrics.add_dimensions(service="orders", team="backend")

ALB URL-decode query parameters

Docs

A new decode_query_parameters flag in ALBResolver automatically URL-decodes query parameter keys and values.

from aws_lambda_powertools.event_handler import ALBResolver

app = ALBResolver(decode_query_parameters=True)

@app.get("/search")
def search():
    # Query params are automatically URL-decoded
    query = app.current_event.query_string_parameters
    return {"query": query}

Changes

🌟New features and non-breaking changes

πŸ“œ Documentation updates

  • chore(deps): bump squidfunk/mkdocs-material from 3bba0a9 to 8f41b60 in /docs (#8010) by @dependabot[bot]
  • docs: clarify append_context_keys behavior with overlapping keys (#7846) by @oyiz-michael

πŸ› Bug and hot fixes

  • fix(logger): preserve percent-style formatting args in flush_buffer (#8009) by @dreamorosi
  • fix(parameters): fix variable shadowing in SSM parameter chunking (#8006) by @dreamorosi
  • fix(event_handler): return 415 status_code for unsupported content-type headers (#7980) by @chriselion
  • fix(typing): resolve ty diagnostics in logging and metrics modules (#7953) by @ConnorKirk
  • fix(event-handler): prevent OpenAPI schema bleed when reusing response dictionaries (#7952) by @oyiz-michael
  • fix(event_handler): sync alias and validation_alias for Pydantic 2.12+ compatibility (#7901) by @leandrodamascena
  • fix(typing): accept Mapping type in resolve() for event parameter (#7909) by @Iamrodos
  • fix(event_handler): fix bug regression in Annotated field (#7904) by @leandrodamascena
  • fix(event_handler): preserve openapi_examples on Body (#7862) by @facu-01

πŸ”§ Maintenance

This release was made possible by the following contributors:

@ConnorKirk, @Iamrodos, @chriselion, @dependabot[bot], @dreamorosi, @facu-01, @github-actions[bot], @leandrodamascena, @maxrabin, @oyiz-michael, dependabot[bot] and github-actions[bot]

Don't miss a new powertools-lambda-python release

NewReleases is sending notifications on new releases.