Skip to content

Releases: aws-powertools/powertools-lambda-python

v2.28.1

28 Nov 00:47
Compare
Choose a tag to compare

Summary

This patch release fixes a bug on the event handler utility, where using the compress option was causing an error.

Huge thanks to @dacianf for reporting this!

Changes

This release was made possible by the following contributors:

@github-actions, @github-actions[bot] and @rubenfonseca

v2.28.0

23 Nov 16:30
Compare
Choose a tag to compare

Summary

This release adds support for Data Validation and automatic OpenAPI generation in Event Handler.

Even better, it works with your existing resolver (API Gateway REST/HTTP, ALB, Lambda Function URL, VPC Lattice)!

Did you read that correctly? Yes, you did! Look at this:

image (9)

Data validation

Docs: Data validation

By adding enable_validation=True to your resolver constructor, you’ll change the way the resolver works. We will:

  1. inspect your route handlers to gather input and output types (including Pydantic models and dataclasses)
  2. validate and coerce the input data for you automatically before invoking your route handlers
  3. validate and coerce the output data for you automatically after invoking your route handlers
  4. enable a cool feature (see the next section!)

This moves data validation responsibilities to Event Handler resolvers, reducing a ton of boilerplate code. You can now focus on just writing your business logic, and leave the validation to us!

from typing import List, Optional

import requests
from pydantic import BaseModel, Field

from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext

tracer = Tracer()
logger = Logger()
app = APIGatewayRestResolver(enable_validation=True)  


class Todo(BaseModel):  
    userId: int
    id_: Optional[int] = Field(alias="id", default=None)
    title: str
    completed: bool


@app.post("/todos")
def create_todo(todo: Todo) -> str:  
    response = requests.post("https://jsonplaceholder.typicode.com/todos", json=todo.dict(by_alias=True))
    response.raise_for_status()

    return response.json()["id"]  


@app.get("/todos")
@tracer.capture_method
def get_todos() -> List[Todo]:
    todo = requests.get("https://jsonplaceholder.typicode.com/todos")
    todo.raise_for_status()

    return todo.json()  


@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_HTTP)
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

OpenAPI generation

Docs: OpenAPI generation

When you enable data validation, we automatically inspect your API in a way that makes it possible to generate OpenAPI specifications automatically!

You can export the OpenAPI spec for customization, manipulation, merging micro-functions, etc., in two ways:

  • Pydantic model using app.get_openapi_schema()
  • JSON Schema using app.get_openapi_json_schema()

Here’s one way to print the schema if you were to run your Python Lambda handler locally:

import requests

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.event_handler.openapi.models import Contact, Server
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver(enable_validation=True)


@app.get("/todos/<todo_id>")
def get_todo_title(todo_id: int) -> str:
    todo = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
    todo.raise_for_status()

    return todo.json()["title"]


def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)


if __name__ == "__main__":
    print(
        app.get_openapi_json_schema(
            title="TODO's API",
            version="1.21.3",
            summary="API to manage TODOs",
            description="This API implements all the CRUD operations for the TODO app",
            tags=["todos"],
            servers=[Server(url="https://stg.example.org/orders", description="Staging server")],
            contact=Contact(name="John Smith", email="[email protected]"),
        ),
    )

Can you see where this is going? Keep reading :)

Swagger UI

Docs: Swagger UI

Last but not least... you can now enable an embedded Swagger UI to visualize and interact with your newly auto-documented API!

from typing import List, Optional

import requests
from pydantic import BaseModel, Field

from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver(enable_validation=True)  
app.enable_swagger()  # by default, path="/swagger"

@app.get("/todos")
@tracer.capture_method
def get_todos() -> List[Todo]:
    todo = requests.get("https://jsonplaceholder.typicode.com/todos")
    todo.raise_for_status()

    return todo.json()
    
def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

The Swagger UI appears by default at the /swagger path, but you can customize this to serve the documentation from another path, and specify the source for Swagger UI assets.

image (10)

We can’t wait for you try this new features!

Changes

  • fix(event_handler): fix format for OpenAPI path templating (#3399) by @rubenfonseca
  • fix(event_handler): allow fine grained Response with data validation (#3394) by @rubenfonseca
  • fix(event_handler): apply serialization as the last operation for middlewares (#3392) by @rubenfonseca

🌟New features and non-breaking changes

  • feat(event_handler): allow customers to catch request validation errors (#3396) by @rubenfonseca

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

  • chore(deps-dev): bump the boto-typing group with 1 update (#3400) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.110.0 to 2.110.1 (#3402) by @dependabot
  • chore(deps): bump datadog-lambda from 4.82.0 to 5.83.0 (#3401) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.110.0 to 2.110.1 (#3403) by @dependabot
  • chore(deps-dev): bump pytest-xdist from 3.4.0 to 3.5.0 (#3387) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.35.0 to 1.36.0 (#3388) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3389) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @heitorlessa, and @rubenfonseca

v2.27.1

21 Nov 16:18
Compare
Choose a tag to compare

Summary

This patch release addresses the following issues:

  • Static typing. Mypy/Pyright no longer complains about Logger.addFilter/removeFilter
  • Documentation. Add note in Event Handler that Amazon API Gateway doesn't handle catch all (*/*) binary types when CORS is configured
  • Logger Correlation ID. You can now use Powertools custom JMESPath Functions to extract correlation ID from data serialized in JSON string, Base64, and GZIP -- @logger.inject_lambda_context("powertools_json(body).my_field")

🌟 Big thanks to @rafrafek and @martinber for their critical eye in spotting some of these issues

Changes

🌟New features and non-breaking changes

  • feat(logger): implement addFilter/removeFilter to address static typing errors (#3380) by @heitorlessa

📜 Documentation updates

  • docs(event_handlers): note that CORS and / binary mime type don't work in API Gateway (#3383) by @heitorlessa
  • fix(logger): allow custom JMESPath functions to extract correlation ID (#3382) by @heitorlessa
  • chore(deps): bump squidfunk/mkdocs-material from 2c57e4d to fc42bac in /docs (#3375) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from f486dc9 to 2c57e4d in /docs (#3366) by @dependabot
  • docs(logger): improve ALC messaging in the PT context (#3359) by @heitorlessa
  • docs(logger): Fix ALC link (#3352) by @leandrodamascena

🐛 Bug and hot fixes

  • fix(logger): allow custom JMESPath functions to extract correlation ID (#3382) by @heitorlessa

🔧 Maintenance

  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3374) by @dependabot
  • chore(deps): bump actions/github-script from 7.0.0 to 7.0.1 (#3377) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 2 updates (#3376) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 2c57e4d to fc42bac in /docs (#3375) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.83.2 to 0.83.3 (#3363) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.108.1 to 2.110.0 (#3365) by @dependabot
  • chore(deps-dev): bump ruff from 0.1.5 to 0.1.6 (#3364) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.109.0 to 2.110.0 (#3361) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from f486dc9 to 2c57e4d in /docs (#3366) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 11 updates (#3362) by @dependabot
  • chore(ci): lint and type checking removal in Pydantic v2 quality check (#3360) by @leandrodamascena
  • chore(deps-dev): bump aws-cdk from 2.108.1 to 2.109.0 (#3354) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates (#3353) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @heitorlessa and @leandrodamascena

v2.27.0

16 Nov 15:56
Compare
Choose a tag to compare

Summary

This minor release adds support for two new environments variables to configure the log level in Logger.

You can now configure the log level of for Logger using two new environment variables: AWS_LAMBDA_LOG_LEVEL and POWERTOOLS_LOG_LEVEL.

The new environment variables will work along the existing LOG_LEVEL variable that is now considered legacy and will be removed in the future.

Setting the log level now follows this order:

  1. AWS_LAMBDA_LOG_LEVEL environment variable
  2. Setting the log level in code using the level constructor option, or by calling the logger.setLevel() method
  3. POWERTOOLS_LOG_LEVEL environment variable

Changes

📜 Documentation updates

🔧 Maintenance

  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3345) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.108.0 to 2.108.1 (#3344) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.107.0 to 2.108.1 (#3343) by @dependabot
  • chore(deps): bump datadog-lambda from 4.81.0 to 4.82.0 (#3338) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates (#3340) by @dependabot
  • chore(deps): bump fastjsonschema from 2.18.1 to 2.19.0 (#3337) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.106.1 to 2.108.0 (#3341) by @dependabot
  • chore(deps-dev): bump pytest-xdist from 3.3.1 to 3.4.0 (#3332) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.106.0 to 2.107.0 (#3333) by @dependabot
  • chore(deps): bump actions/github-script from 6.4.1 to 7.0.0 (#3330) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.83.1 to 0.83.2 (#3335) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.34.0 to 1.35.0 (#3334) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3329) by @dependabot
  • chore(deps): bump actions/dependency-review-action from 3.1.2 to 3.1.3 (#3331) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.106.0 to 2.106.1 (#3328) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.105.0 to 2.106.0 (#3319) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.105.0 to 2.106.0 (#3320) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @github-actions, @github-actions[bot] and @leandrodamascena

v2.26.1

10 Nov 13:47
Compare
Choose a tag to compare

Summary

This patch release fixes a regression when using prefix stripping with middlewares on the event handler. It also fixes a mistyped field on the Kinesis Firehose event source, and a problem when getting multiple encrypted SSM parameters.

Huge thanks to @roger-zhangg and @sean-hernon for helping us identifying and fixing these issues.

Changes

  • fix(event_handler): Router prefix mismatch regression after Middleware feat (#3302) by @leandrodamascena
  • fix(event_source): kinesis subsequenceNumber str type to int (#3275) by @roger-zhangg
  • fix(parameters): Respect POWERTOOLS_PARAMETERS_SSM_DECRYPT environment variable when getting multiple ssm parameters. (#3241) by @sean-hernon

📜 Documentation updates

  • chore(deps): bump squidfunk/mkdocs-material from 772e14e to f486dc9 in /docs (#3299) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from df9409b to 772e14e in /docs (#3265) by @dependabot
  • docs(event-handler): fixed SchemaValidationMiddleware link (#3247) by @jvnsg
  • docs(customer-reference): add Vertex Pharmaceuticals as a customer reference (#3210) by @leandrodamascena
  • chore(deps): bump squidfunk/mkdocs-material from cb38dc2 to df9409b in /docs (#3216) by @dependabot

🔧 Maintenance

  • chore(deps-dev): bump ruff from 0.1.4 to 0.1.5 (#3315) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 3 updates (#3314) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3313) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.104.0 to 2.105.0 (#3309) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3310) by @dependabot
  • chore(deps): bump actions/dependency-review-action from 3.1.1 to 3.1.2 (#3308) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.104.0 to 2.105.0 (#3307) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3305) by @dependabot
  • chore(deps): bump actions/dependency-review-action from 3.1.0 to 3.1.1 (#3301) by @dependabot
  • chore(deps): bump zgosalvez/github-actions-ensure-sha-pinned-actions from 3.0.0 to 3.0.1 (#3300) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 772e14e to f486dc9 in /docs (#3299) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates (#3298) by @dependabot
  • chore(deps-dev): bump ruff from 0.1.3 to 0.1.4 (#3297) by @dependabot
  • feat(event_handler): add ability to expose a Swagger UI (#3254) by @rubenfonseca
  • chore(deps-dev): bump aws-cdk-lib from 2.103.1 to 2.104.0 (#3291) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.33.1 to 1.34.0 (#3290) by @dependabot
  • chore(deps): bump zgosalvez/github-actions-ensure-sha-pinned-actions from 2.1.5 to 3.0.0 (#3289) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.103.1 to 2.104.0 (#3288) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3287) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3282) by @dependabot
  • chore(deps): bump zgosalvez/github-actions-ensure-sha-pinned-actions from 2.1.4 to 2.1.5 (#3281) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3278) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.32.0 to 1.33.1 (#3277) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3273) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.83.0 to 0.83.1 (#3274) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.103.0 to 2.103.1 (#3264) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.103.0 to 2.103.1 (#3263) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from df9409b to 772e14e in /docs (#3265) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.102.0 to 2.103.0 (#3259) by @dependabot
  • chore(deps-dev): bump ruff from 0.1.2 to 0.1.3 (#3257) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.102.0 to 2.103.0 (#3258) by @dependabot
  • chore(deps): bump actions/setup-node from 3.8.1 to 4.0.0 (#3244) by @dependabot
  • chore(deps-dev): bump pytest from 7.4.2 to 7.4.3 (#3249) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates (#3248) by @dependabot
  • chore(deps-dev): bump ruff from 0.1.1 to 0.1.2 (#3250) by @dependabot
  • feat(event_handler): generate OpenAPI specifications and validate input/output (#3109) by @rubenfonseca
  • chore(deps-dev): bump the boto-typing group with 2 updates (#3242) by @dependabot
  • chore(deps): bump ossf/scorecard-action from 2.3.0 to 2.3.1 (#3245) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.82.2 to 0.83.0 (#3243) by @dependabot
  • chore(deps-dev): bump ruff from 0.1.0 to 0.1.1 (#3235) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3231) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.101.1 to 2.102.0 (#3232) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.82.0 to 0.82.2 (#3229) by @dependabot
  • chore(deps): bump datadog-lambda from 4.80.0 to 4.81.0 (#3228) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.81.0 to 0.82.0 (#3224) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.101.0 to 2.101.1 (#3223) by @dependabot
  • chore(deps): bump urllib3 from 1.26.17 to 1.26.18 (#3222) by @dependabot
  • chore(deps-dev): bump urllib3 from 1.26.17 to 1.26.18 in /layer (#3221) by @dependabot
  • chore(deps): bump actions/checkout from 4.1.0 to 4.1.1 (#3220) by @dependabot
  • chore(deps): bump release-drafter/release-drafter from 5.24.0 to 5.25.0 (#3219) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.292 to 0.1.0 (#3213) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.100.0 to 2.101.1 (#3217) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.100.0 to 2.101.0 (#3214) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from cb38dc2 to df9409b in /docs (#3216) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3215) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 2 updates (#3211) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @jvnsg, @leandrodamascena, @roger-zhangg, @rubenfonseca and @sean-hernon

v2.26.0

13 Oct 16:49
Compare
Choose a tag to compare

v2.26.0 Release notes

Summary

This release adds richer exception details to the logger utility, support for VPC Lattice Payload V2, smarter model inference in the parser utility, expanded ARM64 Lambda Layer support on additional regions, and fixes some bugs!

⭐ Huge thanks to our new contributors: @Tom01098, @stevrobu, and @pgrzesik!

Richer exception details

Docs: logger

The logger utility now logs exceptions in a structured format to simplify debugging. Previously, exception tracebacks appeared as a single string containing the raw stack trace frames. Developers had to parse each frame manually to extract file names, line numbers, function names, etc.

With the new serialize_stacktrace flag, the logger prints stack traces as structured JSON. This clearly surfaces exception details like filenames, lines, functions, and statements per frame. The structured output eliminates the need to parse traceback strings, improving observability and accelerating root cause analysis.

image

image

Amazon VPC Lattice Payload V2

Docs: event handler, parser

Amazon VPC Lattice is a fully managed application networking service that you use to connect, secure, and monitor the services for your application across multiple accounts and virtual private clouds (VPC). You can register your Lambda functions as targets with a VPC Lattice target group, and configure a listener rule to forward requests to the target group for your Lambda function.

With this seamless integration, you can now leverage the performance benefits of Amazon VPC Lattice Payload V2 directly in your event handlers. The latest release enables handling Lattice events using the familiar event handler API you already know, including critical features like CORS support and response serialization.

image

Model inference in the parser utility

Docs: parser

The event_parser decorator previously required you to duplicate the type when using type hints. Now, the event_parser decorator can infer the event type directly from your handler signature. This avoids having to redeclare the type in the event_parser decorator.

image

Changes

🌟New features and non-breaking changes

📜 Documentation updates

  • fix(logger): force Logger to use local timezone when UTC flag is not set (#3168) by @roger-zhangg
  • docs(event_handler): add information about case-insensitive header lookup function (#3183) by @pgrzesik
  • chore(deps): bump squidfunk/mkdocs-material from a4cfa88 to cb38dc2 in /docs (#3189) by @dependabot
  • chore(deps): bump gitpython from 3.1.35 to 3.1.37 in /docs (#3188) by @dependabot
  • docs(contributing): initial structure for revamped contributing guide (#3133) by @heitorlessa
  • chore(deps): bump squidfunk/mkdocs-material from cbfecae to a4cfa88 in /docs (#3175) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from e5f28aa to cbfecae in /docs (#3157) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 06673a1 to e5f28aa in /docs (#3134) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from b41ba6d to 06673a1 in /docs (#3124) by @dependabot

🐛 Bug and hot fixes

🔧 Maintenance

  • fix(logger): force Logger to use local timezone when UTC flag is not set (#3168) by @roger-zhangg
  • chore(deps-dev): bump the boto-typing group with 1 update (#3196) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3198) by @dependabot
  • chore(deps): bump aws-xray-sdk from 2.12.0 to 2.12.1 (#3197) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.31.0 to 1.32.0 (#3192) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from a4cfa88 to cb38dc2 in /docs (#3189) by @dependabot
  • chore(deps): bump gitpython from 3.1.35 to 3.1.37 in /docs (#3188) by @dependabot
  • feat(logger): new stack_trace field with rich exception details (#3147) by @stevrobu
  • chore(deps-dev): bump aws-cdk from 2.99.1 to 2.100.0 (#3185) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#3177) by @dependabot
  • chore(deps): bump ossf/scorecard-action from 2.2.0 to 2.3.0 (#3178) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.80.4 to 0.81.0 (#3179) by @dependabot
  • docs(contributing): initial structure for revamped contributing guide (#3133) by @heitorlessa
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3174) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from cbfecae to a4cfa88 in /docs (#3175) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3170) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.80.3 to 0.80.4 (#3166) by @dependabot
  • chore(deps-dev): bump urllib3 from 1.26.16 to 1.26.17 in /layer (#3163) by @dependabot
  • chore(deps): bump urllib3 from 1.26.16 to 1.26.17 (#3162) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.291 to 0.0.292 (#3161) by @dependabot
  • chore(deps): bump fastjsonschema from 2.18.0 to 2.18.1 (#3159) by @dependabot
  • chore(deps): bump actions/setup-python from 4.7.0 to 4.7.1 (#3158) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.99.0 to 2.99.1 (#3155) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3156) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from e5f28aa to cbfecae in /docs (#3157) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.98.0 to 2.99.0 (#3148) by @dependabot
  • chore(deps-dev): bump types-requests from 2.31.0.5 to 2.31.0.6 (#3145) by @dependabot
  • chore(deps): bump pydantic from 1.10.12 to 1.10.13 (#3144) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 2 updates (#3143) by @dependabot
  • feat(data_masking): add new sensitive data masking utility (#2197) by @seshubaws
  • chore(deps-dev): bump aws-cdk from 2.97.0 to 2.98.0 (#3139) by @dependabot
  • chore(deps-dev): bump types-requests from 2.31.0.3 to 2.31.0.5 (#3136) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3135) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 06673a1 to e5f28aa in /docs (#3134) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.290 to 0.0.291 (#3126) by @dependabot
  • chore(deps): bump actions/checkout from 4.0.0 to 4.1.0 (#3128) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.96.2 to 2.97.0 (#3129) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3127) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.80.2 to 0.80.3 (#3125) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from b41ba6d to 06673a1 in /docs (#3124) by @dependabot

This release was made possible by the following contributors:

@Tom01098, @dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @heitorlessa, @leandrodamascena, @rubenfonseca, @pgrzesik, @roger-zhangg, @seshubaws, @stephenbawks and @stevrobu

v2.25.1

22 Sep 13:46
Compare
Choose a tag to compare

Summary

This is a patch release to address a bug in @metrics.log_metrics decorator to support functions with arbitrary arguments/kwargs, and a minor typing fix in Logger for explicit None return types.

🌟 Huge thanks to two new contributors who reported and fixed both bugs @FollowTheProcess and @thegeorgeliu

Changes

📜 Documentation updates

  • chore(deps): bump squidfunk/mkdocs-material from 4ff781e to b41ba6d in /docs (#3117) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from c4890ab to 4ff781e in /docs (#3110) by @dependabot

🐛 Bug and hot fixes

  • fix(logger): add explicit None return type annotations (#3113) by @FollowTheProcess
  • fix(metrics): support additional arguments in functions wrapped with log_metrics decorator (#3120) by @thegeorgeliu

🔧 Maintenance

  • chore(deps): bump squidfunk/mkdocs-material from 4ff781e to b41ba6d in /docs (#3117) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 3 updates (#3118) by @dependabot
  • chore(deps-dev): bump types-requests from 2.31.0.2 to 2.31.0.3 (#3114) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3115) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3108) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from c4890ab to 4ff781e in /docs (#3110) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.79.11 to 0.80.2 (#3107) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.289 to 0.0.290 (#3105) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.96.1 to 2.96.2 (#3102) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3101) by @dependabot

This release was made possible by the following contributors:

@FollowTheProcess, @dependabot, @dependabot[bot], @github-actions, @github-actions[bot] and @thegeorgeliu

v2.25.0

15 Sep 15:05
Compare
Choose a tag to compare

Summary

This release simplifies data transformation with Amazon Kinesis Data Firehose, and handling secret rotation events from Amazon Secrets Manager.

🌟 Huge welcome to our new contributor @TonySherman. Tony documented how to use Event Handler with micro Lambda functions.

Data Transformation code snippet

Data transformation

Docs

When using Kinesis Firehose, you can use a Lambda function to perform data transformation. For each transformed record, you can choose to either:

  • A) Put them back to the delivery stream (default)
  • B) Drop them so consumers don't receive them (e.g., data validation)
  • C) Indicate a record failed data transformation and should be retried

To make this process easier, you can now use KinesisFirehoseDataTransformationResponse and serialization functions to quickly encode payloads into base64 data for the stream.

Example where you might want to drop unwanted records from the stream.

from json import JSONDecodeError
from typing import Dict

from aws_lambda_powertools.utilities.data_classes import (
    KinesisFirehoseDataTransformationRecord,
    KinesisFirehoseDataTransformationResponse,
    KinesisFirehoseEvent,
    event_source,
)
from aws_lambda_powertools.utilities.serialization import base64_from_json
from aws_lambda_powertools.utilities.typing import LambdaContext


@event_source(data_class=KinesisFirehoseEvent)
def lambda_handler(event: KinesisFirehoseEvent, context: LambdaContext):
    result = KinesisFirehoseDataTransformationResponse()

    for record in event.records:
        try:
            payload: Dict = record.data_as_json  # decodes and deserialize base64 JSON string

            ## generate data to return
            transformed_data = {"tool_used": "powertools_dataclass", "original_payload": payload}

            processed_record = KinesisFirehoseDataTransformationRecord(
                record_id=record.record_id,
                data=base64_from_json(transformed_data),
            )
        except JSONDecodeError:  
            # our producers ingest JSON payloads only; drop malformed records from the stream
            processed_record = KinesisFirehoseDataTransformationRecord(
                record_id=record.record_id,
                data=record.data,
                result="Dropped",
            )

        result.add_record(processed_record)

    # return transformed records
    return result.asdict()

Rotating secrets

Docs

When rotating secrets with Secrets Manager, it invokes your Lambda function in four potential steps:

  • createSecret. Create a new version of the secret.
  • setSecret. Change the credentials in the database or service.
  • testSecret. Test the new secret version.
  • finishSecret. Finish the rotation.

You can now use SecretsManagerEvent to more easily access the event structure, and combine Parameters to get secrets to perform secret operations.

from aws_lambda_powertools.utilities import parameters
from aws_lambda_powertools.utilities.data_classes import SecretsManagerEvent, event_source

secrets_provider = parameters.SecretsProvider()


@event_source(data_class=SecretsManagerEvent)
def lambda_handler(event: SecretsManagerEvent, context):
    # Getting secret value using Parameter utility
    # See https://docs.powertools.aws.dev/lambda/python/latest/utilities/parameters/
    secret = secrets_provider.get(event.secret_id, VersionId=event.version_id, VersionStage="AWSCURRENT")

    if event.step == "setSecret":
        # Perform any secret rotation logic, e.g., change DB password
        # Check more examples: https://github.com/aws-samples/aws-secrets-manager-rotation-lambdas
        print("Rotating secret...")

    return secret

Changes

🌟New features and non-breaking changes

  • feat(event_source): add Kinesis Firehose Data Transformation data class (#3029) by @roger-zhangg
  • feat(event_sources): add Secrets Manager secret rotation event (#3061) by @roger-zhangg

📜 Documentation updates

🔧 Maintenance

  • chore(deps-dev): bump aws-cdk from 2.96.0 to 2.96.1 (#3093) by @dependabot
  • chore(typing): move backwards compat types to shared types (#3092) by @heitorlessa
  • refactor(parameters): BaseProvider._get to also support Dict (#3090) by @leandrodamascena
  • chore(deps): bump docker/setup-qemu-action from 2.2.0 to 3.0.0 (#3081) by @dependabot
  • chore(deps): bump docker/setup-buildx-action from 2.10.0 to 3.0.0 (#3083) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.79.10 to 0.79.11 (#3088) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.30.0 to 1.31.0 (#3086) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.95.1 to 2.96.0 (#3087) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3085) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.288 to 0.0.289 (#3080) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.79.9 to 0.79.10 (#3077) by @dependabot
  • chore(deps-dev): bump hvac from 1.2.0 to 1.2.1 (#3075) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from dd1770c to c4890ab in /docs (#3078) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.287 to 0.0.288 (#3076) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.95.0 to 2.95.1 (#3074) by @dependabot
  • chore(deps): bump actions/dependency-review-action from 3.0.8 to 3.1.0 (#3071) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.94.0 to 2.95.0 (#3070) by @dependabot
  • chore(automation): remove previous labels when PR is updated (#3066) by @sthulb

This release was made possible by the following contributors:

@TonySherman, @dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @heitorlessa, @leandrodamascena, @roger-zhangg and @sthulb

v2.24.0

08 Sep 13:37
Compare
Choose a tag to compare

Summary

This release brings custom serialization/deserialization to Idempotency, and Middleware support in Event Handler (API Gateway REST/HTTP, ALB, Lambda Function URL, VPC Lattice). Oh didn't I say some bug fixes too? 🙏

🌟 Big welcome to the new contributors: @adriantomas, @aradyaron, @nejcskofic, @waveFrontSet

Middleware launch

Idempotency custom serialization

Docs
🌟 Huge thanks to @aradyaron!!

Previously, any function annotated with @idempotent_function will have its return type as a JSON object - this was challenging for customers using Pydantic, Dataclasses, or any custom types.

You can now use output_serializer to automatically serialize the return type for Dataclasses or Pydantic, and bring your own serializer/deserializer too!

from aws_lambda_powertools.utilities.idempotency import (
    DynamoDBPersistenceLayer,
    IdempotencyConfig,
    idempotent_function,
)
from aws_lambda_powertools.utilities.idempotency.serialization.pydantic import PydanticSerializer
from aws_lambda_powertools.utilities.parser import BaseModel
from aws_lambda_powertools.utilities.typing import LambdaContext

dynamodb = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
config = IdempotencyConfig(event_key_jmespath="order_id")  # see Choosing a payload subset section


class OrderItem(BaseModel):
    sku: str
    description: str


class Order(BaseModel):
    item: OrderItem
    order_id: int


class OrderOutput(BaseModel):
    order_id: int


@idempotent_function(
    data_keyword_argument="order",
    config=config,
    persistence_store=dynamodb,
    output_serializer=PydanticSerializer,
)
# order output is inferred from return type
def process_order(order: Order) -> OrderOutput:
    return OrderOutput(order_id=order.order_id)


def lambda_handler(event: dict, context: LambdaContext):
    config.register_lambda_context(context)  # see Lambda timeouts section
    order_item = OrderItem(sku="fake", description="sample")
    order = Order(item=order_item, order_id=1)

    # `order` parameter must be called as a keyword argument to work
    process_order(order=order)

Middleware in Event Handler

Docs
🌟 Huge thanks to @walmsles for the implementation and marvelous illustrations!!

image

You can now bring your own middleware to run logic before or after requests when using Event Handler.

The goal continues to be having built-in features over middlewares, so you don't have to own boilerplate code. That said, we recognize we can't virtually cover every use case - that's where middleware comes in!

Example using per-route and global middlewares

import middleware_global_middlewares_module
import requests

from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response

app = APIGatewayRestResolver()
logger = Logger()

app.use(middlewares=[middleware_global_middlewares_module.log_request_response])


@app.get("/todos", middlewares=[middleware_global_middlewares_module.inject_correlation_id])
def get_todos():
    todos: Response = requests.get("https://jsonplaceholder.typicode.com/todos")
    todos.raise_for_status()

    return {"todos": todos.json()[:10]}


@logger.inject_lambda_context
def lambda_handler(event, context):
    return app.resolve(event, context)

Changes

🌟New features and non-breaking changes

  • feat(event_handler): add Middleware support for REST Event Handler (#2917) by @walmsles
  • feat(idempotency): add support to custom serialization/deserialization on idempotency decorator (#2951) by @aradyaron

📜 Documentation updates

  • feat(event_handler): add Middleware support for REST Event Handler (#2917) by @walmsles
  • feat(idempotency): add support to custom serialization/deserialization on idempotency decorator (#2951) by @aradyaron
  • chore(deps): bump squidfunk/mkdocs-material from f4764d1 to dd1770c in /docs (#3044) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from b1f7f94 to f4764d1 in /docs (#3031) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 97da15b to b1f7f94 in /docs (#3021) by @dependabot

🐛 Bug and hot fixes

  • fix(parser): change ApproximateCreationDateTime field to datetime in DynamoDBStreamChangedRecordModel (#3049) by @waveFrontSet
  • fix(event_handler): expanding safe URI characters to include +$& (#3026) by @nejcskofic

🔧 Maintenance

  • chore(deps-dev): bump pytest from 7.4.1 to 7.4.2 (#3057) by @dependabot
  • chore(deps): bump actions/upload-artifact from 3.1.2 to 3.1.3 (#3053) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update (#3052) by @dependabot
  • chore(deps-dev): bump hvac from 1.1.1 to 1.2.0 (#3054) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.79.8 to 0.79.9 (#3046) by @dependabot
  • chore(deps): bump actions/checkout from 3.6.0 to 4.0.0 (#3041) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 9.2.6 to 9.2.7 (#3043) by @dependabot
  • chore(deps-dev): bump pytest from 7.4.0 to 7.4.1 (#3042) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from f4764d1 to dd1770c in /docs (#3044) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.93.0 to 2.94.0 (#3036) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.286 to 0.0.287 (#3035) by @dependabot
  • chore(deps-dev): bump cfn-lint from 0.79.7 to 0.79.8 (#3033) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from b1f7f94 to f4764d1 in /docs (#3031) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 9.2.5 to 9.2.6 (#3032) by @dependabot
  • chore(deps-dev): bump sentry-sdk from 1.29.2 to 1.30.0 (#3028) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 11 updates (#3027) by @dependabot
  • chore(deps): bump docker/setup-buildx-action from 2.9.1 to 2.10.0 (#3022) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from 97da15b to b1f7f94 in /docs (#3021) by @dependabot
  • chore(deps-dev): bump the boto-typing group with 1 update (#3013) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.285 to 0.0.286 (#3014) by @dependabot

This release was made possible by the following contributors:

@adriantomas, @aradyaron, @dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @nejcskofic, @walmsles and @waveFrontSet

v2.23.1

25 Aug 16:17
Compare
Choose a tag to compare

Summary

This patch release primarily addresses a fix for customers who utilize default tags and metric-specific tags within the Datadog Metrics provider. Tags are now merged seamlessly, effectively resolving precedence conflicts that can arise when using tags with the same key.

image

The newly generated metric is now:

{
    "m": "SuccessfulBooking",
    "v": 1,
    "e": 1692736997,
    "t": [
        "product:ticket"
        "flight:AB123",
    ]
}

🌟 Huge thanks to @ecokes for reporting and reproducing it.

Changes

📜 Documentation updates

  • chore(deps): bump squidfunk/mkdocs-material from cd3a522 to 97da15b in /docs (#2987) by @dependabot

🐛 Bug and hot fixes

🔧 Maintenance

  • chore(deps): bump aws-actions/configure-aws-credentials from 2.2.0 to 3.0.0 (#3000) by @dependabot
  • chore(deps): bump actions/checkout from 3.5.3 to 3.6.0 (#2999) by @dependabot
  • fix(metrics): preserve default_tags when metric-specific tag is set in Datadog provider (#2997) by @leandrodamascena
  • chore(deps): bump slsa-framework/slsa-github-generator from 1.8.0 to 1.9.0 (#2992) by @dependabot
  • chore(deps-dev): bump aws-cdk from 2.92.0 to 2.93.0 (#2993) by @dependabot
  • chore(deps): bump squidfunk/mkdocs-material from cd3a522 to 97da15b in /docs (#2987) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 9.2.0 to 9.2.3 (#2988) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 9.1.21 to 9.2.0 (#2984) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#2983) by @dependabot
  • chore(deps-dev): bump ruff from 0.0.284 to 0.0.285 (#2977) by @dependabot
  • chore(deps): bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates (#2978) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @github-actions, @github-actions[bot], @leandrodamascena and @rubenfonseca