Skip to content

Releases: aws-powertools/powertools-lambda-python

v2.0.0

24 Oct 08:08

Choose a tag to compare

Summary

We are extremely happy to announce the smallest release version ever - v2.0.0 🎉🎉!

The number one customer request was reducing package size. Some customers use a different tracing provider. Others used Parser (Pydantic) for data modelling and deep data validation instead of JSON Schema Validation. A few brought large machine learning models and every bit of space they can save matters.

The number two request was ARM64 support. Customers want to benefit from performance and cost savings for their workloads. However, they don’t want to invest additional time testing and compiling dependencies they use daily for ARM64.

We’ve spent the past 2 months optimizing as much as we could. We kept breaking changes to a minimum to make your transition to v2 as smooth as possible.

For backwards incompatible changes, we’ve spent considerable effort making sure they are visible, why we implemented them, and and what to do if they affect you.

Our sincerest appreciation for the community help and patience while we’ve worked on this release - Thank you ❤️!


Table of contents

What's New in V2

Python compatibility

We dropped support for Python 3.6. We highly recommend moving to the latest Python available in AWS Lambda (3.9).

Package size reduction by 97.6%

We now rely on AWS SDK available in the Lambda runtime, and all other dependencies are marked as optional.

There are subtle but important differences in the installation experience - PyPi (all optional) and Lambda Layer (all included).

PyPi

The compressed package size is now approximately 240K (previously 10M).

We updated each documentation to emphasize when an additional dependency is required (Tracer, Validation and Parser). If you prefer to install all of them, use pip install aws-lambda-powertools[all].

Note. If you need to use newer AWS services or features not available in the Lambda runtime provided SDK, you'll need to bundle boto3 as a dependency.

Lambda Layer

The compressed package size is now approximately 2M (previously 17M).

Lambda Layer includes all dependencies. They're also optimized for package size and speed (Pydantic now compiled with Cython for ~30-50% speed gain).

ARM Support

We now offer full support to ARM via Lambda Layer and SAR installation. All C-extension dependencies are compiled, optimized and tested against Lambda environment.

PyPi and Lambda Layer available upon release notes event

You can now safely subscribe to GitHub Release event to know when PyPi and Lambda Layer ARNs have the latest version.

Previously, PyPi, Lambda Layers, and docs were updated after a release notes went live to GitHub (~15m completion). Due to Lambda Layer compilation (x86/ARM64), this process takes on average 30m longer.

As such, we make releases prior to sharing release notes, guaranteeing for customers watching for GitHub Releases that Layer ARNs available in the documentation match PyPi releases (no more delays).

Event Handler REST new features

Multi-value header and cookies support

When returning custom responses, you now can add a list of values for a header, including cookies.

Event Handler will seamless adapt to the expected format based on resolver used, whether that is REST API, HTTP API, ALB, or Function URL.

from http import HTTPStatus
from uuid import uuid4

import requests

from aws_lambda_powertools.event_handler import (
    APIGatewayRestResolver,
    Response,
    content_types,
)
from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver()


@app.get("/todos")
def get_todos():
    todos: requests.Response = requests.get("https://jsonplaceholder.typicode.com/todos")
    todos.raise_for_status()

    dummy_transactions = [f"{uuid4()}", f"{uuid4()}", f"{uuid4()}"]
    multi_value_header = {"X-Transaction-Id": dummy_transactions}

    return Response(
        status_code=HTTPStatus.OK.value,  # 200
        content_type=content_types.APPLICATION_JSON,
        body=todos.json()[:10],
        headers=multi_value_header,  # NEW
        cookies=[Cookie(name="session_id", value="12345")],  # NEW
    )

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

NOTE. For ALB, you have to explicitly enable multi-value headers in the target configuration.

Trailing slash route support

APIGatewayRestResolver now seamless support route resolution with trailing slashes: /todos/.

Previously, requests with a trailing slash would return HTTP 404 due to route mismatch.

Note. This was not necessary for HTTP API and ALB.

Fully qualified names for Tracer subsegments

tracer.capture_method or tracer.capture_lambda_handler decorators now use the decorated function or method fully qualified name as the subsegment name.

This enables accurate traces for ABC or Protocol classes, where their method name will be the same but for distinct classes.

image

Backwards incompatible change in v2

Here’s a quick view of deprecated features removed and backwards incompatible changes.

Area Change Code change required IAM Permissions change required
Batch Removed legacy SQS batch processor in favour of BatchProcessor. Yes -
Environment variables Removed legacy POWERTOOLS_EVENT_HANDLER_DEBUG in favour of [POWERTOOLS_DEV](https://awslabs.github.io/aws-lambda-powertools-python...
Read more

v1.31.1

14 Oct 14:34
abb8043

Choose a tag to compare

Summary

This patch release is focused on Parser with SNS FIFO.

When using SNS FIFO topics, SNS removes three fields, namely: SigningCertUrl, Signature, and SignatureVersion. As such, we're marking these fields as Optional to prevent ValidationError. Thanks to @plondino for flagging this.

NOTE: In the future, we'll be looking at creating separate FIFO Models.

Hacktoberfest

Big thanks to @digitalisx and @senmm who helped addresses typos in the documentation. Thank you for helping make the documentation better for everyone 💞!

Changes

NOTE: This release will be available in PyPi in roughly 5m, and Lambda Layers across all AWS commercial regions in ~15m.

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(parser): loose validation on SNS fields to support FIFO (#1606) by @heitorlessa

🔧 Maintenance

  • docs(governance): allow community to suggest feature content (#1593) by @heitorlessa
  • chore(deps-dev): bump mypy-boto3-ssm from 1.24.81 to 1.24.90 (#1594) by @dependabot
  • chore(deps-dev): bump flake8-builtins from 1.5.3 to 2.0.0 (#1582) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @digitalisx, @eldritchideen, @heitorlessa, @rubenfonseca, @senmm and Release bot

v1.31.0

10 Oct 16:13
7cb937e

Choose a tag to compare

Summary

This release fixes a bug in Metrics where subsequent instances didn't share a dimensions set - Huge thanks to @cfchou for flagging it and for being super proactive in creating a test ahead of time.

This also adds support for Amazon Kinesis Firehose in Parser - big thanks to @ran-isenberg!

image

Changes

🌟New features and non-breaking changes

🐛 Bug and hot fixes

  • fix(metrics): ensure dimension_set is reused across instances (pointer) (#1581) by @heitorlessa

🔧 Maintenance

  • chore(deps-dev): bump types-requests from 2.28.11.1 to 2.28.11.2 (#1576) by @dependabot
  • chore(deps-dev): bump typing-extensions from 4.3.0 to 4.4.0 (#1575) by @dependabot

This release was made possible by the following contributors:

@am29d, @dependabot, @dependabot[bot], @heitorlessa, @ran-isenberg and Release bot

v1.30.0

05 Oct 13:01
1709b7c

Choose a tag to compare

Summary

This release adds support for (1) Lambda context in Batch processing, (2) Context sharing support in REST and GraphQL APIs, and (3) Consolidate features to make prototyping local/non-prod environments easier. Bug fixes and other minor improvements are at the bottom.

image

Accessing Lambda context in Batch processing

Docs

You can now opt-in to receive a Lambda context object if your function has a parameter named lambda_context.

This unlocks long-running data pipelines, where you need to know how much time you have left before your function times out - thanks to @mew1033 for the feature request.

from typing import Optional

from aws_lambda_powertools.utilities.batch import (BatchProcessor, EventType,
                                                   batch_processor)
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
from aws_lambda_powertools.utilities.typing import LambdaContext

processor = BatchProcessor(event_type=EventType.SQS) # or DynamoDB, Kinesis

# lambda_context will be populated at runtime
def record_handler(record: SQSRecord, lambda_context: Optional[LambdaContext] = None): ...

@batch_processor(record_handler=record_handler, processor=processor)
def lambda_handler(event, context: LambdaContext):
    return processor.response()

New context support in Event Handler (REST and GraphQL)

Docs

You can now inject contextual information before or during event routing. This is the precursor to Middleware support in Event Handler. This unlocks two common use cases:

  • You split routes using Router() feature, and you need to pass data from App() without running into potential circular import issues
  • You have custom logic to run before every event, and want to expose the result to any registered route with minimal effort

Thanks to @MaartenUreel for the feature request, and @benbridts, @gwlester, and @walmsles for the discussion to get to an optimal UX.

UX

Entrypoint: app.py

import todos

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver()
app.include_router(todos.router)


def lambda_handler(event: dict, context: LambdaContext) -> dict:
    app.append_context(is_admin=True)  # arbitrary number of key=value data
    return app.resolve(event, context)

todos.py

import requests
from requests import Response

from aws_lambda_powertools.event_handler.api_gateway import Router


ENDPOINT = "https://jsonplaceholder.typicode.com/todos"

router = Router()

@router.get("/todos")
def get_todos():
    is_admin: bool = router.context.get("is_admin", False)
    todos = {}

    if is_admin:
        todos: Response = requests.get(ENDPOINT)
        todos.raise_for_status()
        todos = todos.json()[:10]

    return {"todos": todos}

Optimizing for non-production environments

Docs

Thanks to @pmarko1711, Logger now uses pretty-print when you set POWERTOOLS_DEV=1 environment variable. This also helps us consolidate features where we can make it easier to prototype locally or against a non-production environment.

Debug mode simplified

When raising bug reports, you can now get Lambda Powertools debug logs with POWERTOOLS_DEBUG=1. Previously, you had to change your source code to explicitly enable debugging in Powertools.

Changes

🌟New features and non-breaking changes

  • feat(logger): introduce POWERTOOLS_DEBUG for internal debugging (#1572) by @heitorlessa
  • feat(logger): include logger name attribute when copy_config_to_registered_logger is used (#1568) by @heitorlessa
  • feat(event-handler): context support to share data between routers (#1567) by @heitorlessa
  • feat(batch): inject lambda_context if record handler signature accepts it (#1561) by @heitorlessa
  • feat(logger): pretty-print JSON when POWERTOOLS_DEV is set (#1548) by @pmarko1711

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(apigateway): update Response class to require status_code only (#1560) by @heitorlessa
  • fix(event_sources): implement Mapping protocol on DictWrapper for better interop with existing middlewares (#1516) by @Tankanow
  • fix(typing): level arg in copy_config_to_registered_loggers (#1534) by @kbakk

🔧 Maintenance

  • chore(multiple): localize powertools_dev env logic and warning (#1570) by @heitorlessa
  • chore(deps-dev): bump types-requests from 2.28.11 to 2.28.11.1 (#1571) by @dependabot
  • chore(deps): bump dependabot/fetch-metadata from 1.3.3 to 1.3.4 (#1565) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 8.5.3 to 8.5.4 (#1563) by @dependabot
  • chore(deps-dev): bump mypy-boto3-secretsmanager from 1.24.54 to 1.24.83 (#1557) by @dependabot
  • chore(deps-dev): bump pytest-cov from 3.0.0 to 4.0.0 (#1551) by @dependabot
  • chore(deps-dev): bump flake8-bugbear from 22.9.11 to 22.9.23 (#1541) by @dependabot
  • fix(event_sources): implement Mapping protocol on DictWrapper for better interop with existing middlewares (#1516) by @Tankanow
  • chore(deps-dev): bump mypy-boto3-ssm from 1.24.80 to 1.24.81 (#1544) by @dependabot
  • chore(deps-dev): bump mypy-boto3-ssm from 1.24.69 to 1.24.80 (#1542) by @dependabot
  • chore(deps-dev): bump mako from 1.2.2 to 1.2.3 (#1537) by @dependabot
  • chore(deps-dev): bump types-requests from 2.28.10 to 2.28.11 (#1538) by @dependabot
  • chore(deps): bump email-validator from 1.2.1 to 1.3.0 (#1533) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 8.5.1 to 8.5.3 (#1532) by @dependabot
  • chore(deps): bump fastjsonschema from 2.16.1 to 2.16.2 (#1530) by @dependabot
  • chore(deps): bump codecov/codecov-action from 3.1.0 to 3.1.1 (#1529) by @dependabot
  • chore(deps): bump actions/setup-python from 3 to 4 (#1528) by @dependabot
  • chore(deps-dev): bump mypy-boto3-s3 from 1.24.36.post1 to 1.24.76 (#1531) by @dependabot

This release was made possible by the following contributors:

@Tankanow, @dependabot, @dependabot[bot], @heitorlessa, @kbakk, @pmarko1711, @rubenfonseca

v1.29.2

19 Sep 13:35
203e7c8

Choose a tag to compare

Summary

This patch release fixes a bug in the Serverless Application Repository (SAR) Extras Layer for customers using Parser/Pydantic, where the module wasn't available.

Changes

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @rubenfonseca and Release bot

v1.29.1

13 Sep 12:36

Choose a tag to compare

Due to a problem with the release pipeline, we had to yank the v1.29.0 release from PyPI. To fix the problem we are releasing v1.29.1 with no additional changes.

Summary

This release adds a new major integration with Apache Kafka (both Amazon Managed Streaming for Apache Kafka (MSK) and self-managed clusters). We also extended the Event Source Data Classes to support CloudWatch dashboard custom widgets.

Apache Kafka

Powertools can now seamlessly consume events sourced from Apache Kafka (MSK, self-managed). Apache Kafka as an event source operates similarly to using Amazon Simple Queue Service (Amazon SQS) or Amazon Kinesis.

You can easily consume a Kafka event by using the KafkaEvent Data Class:

image

If you want extra flexibility and validation, you can also use the Pydantic models KafkaMskEventModel (for Apache MSK) and KafkaSelfManagedEventModel (for self-managed clusters):
carbon (17) (1)
If your Kafka event payload has a known structure, you could also leverage the KafkaEnvelope model.

Thank you @lyoung-confluent and @ran-isenberg for your contribution!

🌟 Would you like to see more integrations between Apache Kafka and Lambda Powertools? Drop us a line in the python channel of our Discord.

CloudWatch dashboards custom widgets

We also added support for handling events generated by CloudWatch dashboard custom widgets:

carbon (18) (1)

Big thanks to @sthuber90 for your contribution!

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🔧 Maintenance

  • chore(deps): bump flake8-bugbear from 22.8.23 to 22.9.11 (#1512) by @dependabot
  • chore(deps): bump mkdocs-material from 8.4.3 to 8.4.4 (#1513) by @dependabot
  • chore(deps): bump types-requests from 2.28.9 to 2.28.10 (#1508) by @dependabot
  • chore(deps): bump aws-cdk-aws-apigatewayv2-integrations-alpha from 2.40.0a0 to 2.41.0a0 (#1510) by @dependabot
  • chore(deps-dev): bump mypy-boto3-ssm from 1.24.39.post2 to 1.24.69 (#1509) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.40.0 to 2.41.0 (#1507) by @dependabot
  • chore(deps-dev): bump aws-cdk-aws-apigatewayv2-integrations-alpha from 2.39.1a0 to 2.40.0a0 (#1496) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 8.4.2 to 8.4.3 (#1504) by @dependabot
  • chore(deps): bump pydantic from 1.10.1 to 1.10.2 (#1502) by @dependabot
  • chore(deps-dev): bump pytest from 7.1.2 to 7.1.3 (#1497) by @dependabot
  • chore(deps-dev): bump black from 22.6.0 to 22.8.0 (#1494) by @dependabot
  • chore(deps-dev): bump aws-cdk-lib from 2.39.1 to 2.40.0 (#1495) by @dependabot
  • chore(maintenance): add discord link to first PR and first issue (#1493) by @rubenfonseca
  • chore(deps): bump pydantic from 1.10.0 to 1.10.1 (#1491) by @dependabot
  • chore(deps-dev): bump flake8-variables-names from 0.0.4 to 0.0.5 (#1490) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 8.4.1 to 8.4.2 (#1483) by @dependabot
  • chore(ci): create reusable docs publishing workflow (#1482) by @heitorlessa
  • chore(deps-dev): bump mypy-boto3-dynamodb from 1.24.55.post1 to 1.24.60 (#1481) by @dependabot
  • chore(ci): add workflow to suggest splitting large PRs (#1480) by @heitorlessa
  • chore(ci): add linter for GitHub Actions as pre-commit hook (#1479) by @heitorlessa
  • chore(deps-dev): bump black from 21.12b0 to 22.8.0 (#1515) by @dependabot
  • chore(deps-dev): bump mkdocs-material from 8.4.4 to 8.5.0 (#1514) by @dependabot
  • chore(ci): add linter for GitHub Actions as pre-commit hook (#1479) by @heitorlessa

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @heitorlessa, @leandrodamascena, @lyoung-confluent, @ran-isenberg, @rubenfonseca, @sthuber90 and Release bot

v1.28.0

25 Aug 09:42

Choose a tag to compare

Summary

This release brings major updates: upcoming v2 to drop Python 3.6 support, Lambda Function URL support in Parser(Pydantic), and.... 🥁 🥁 🥁 our new public Discord Server - join us

Oh hey, please welcome Leandro as our new full-time maintainer - @leandrodamascena🎉

Lambda Function URL support in Parser

This release adds support for Lambda Function URL for Parser (Pydantic Model) - big thanks to @ran-isenberg. It extends the work previously done in v1.27.0 for Event Source Data Classes.

image

Upcoming v2 and breaking changes

We’ve got a new RFC for our first major version v2.0.0 - aiming to end of September. We’re striving to make the bare minimum breaking changes given the timeframe we have. Please get acquainted with the breaking changes (e.g., legacy sqs_batch_processor, Event Handler to support multi-value headers) and do share your feedback.

Improved documentation code snippets

We know that a good documentation is critical for adopting any open-source project. We continue to make progress in rewriting code snippets to be more realistic, and apply our code quality standards like we do for any other change.

In this release, we've refactored the JMESPath Functions,, Validation, Typing, and Middleware factory documentation to include real examples of using these features. You can follow progress on upcoming refactoring in our board of activities.

👀 Take a look at this gigantic yet realistic all-in-one middleware combining Powertools features.

Here’s a sneak peek:

image

image

End-to-testing (E2E)

We’ve published our internal framework to create and run E2E testing via GitHub Actions. This allow us to start working on further complement our functional testing, and soon begin wider coverage on integration tests. We’ll be documenting how customers can contribute E2E soon - you can find the internal details here.

image

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(ci): calculate parallel jobs based on infrastructure needs (#1475) by @heitorlessa

🔧 Maintenance

This release was made possible by the following contributors:

@am29d, @dependabot, @dependabot[bot], @heitorlessa, @leandrodamascena, @peterschutt, @ran-isenberg, @rubenfonseca, @sthuber90 and Release bot

v1.27.0

05 Aug 13:18
3ed48e7

Choose a tag to compare

Summary

This is our feature release after our extended pause, we couldn't be more excited to bring you: Lambda Function URL, Metrics now supports up to 29 dimensions, and Pre-configured GitPod.io dev environment for contributors.

Huge thanks to a new contributor: @leandrodamascena

Event Handler - Lambda Function URL

You can now use LambdaFunctionUrlResolver to seamless develop with Lambda Function URL. Developer experience remains exactly the same for other REST Event Handlers, making it easier to switch between Application Load Balancer, and API Gateway (REST and HTTP) APIs.

Correlation ID support and documentation have been documented accordingly - here's how it looks like!

image

Improved onboarding to first contribution

For new contributors and those new to Python, @leandrodamascena contributed a pre-configured Cloud-based development environment based on Gitpod.io product. When visiting our contribution guide, you will now see a link to instantly spin up a dev environment pre-configured with all dependencies, linters, and git pre-commit hooks to fast track reviews.

image

image

Increasing Metrics dimension limit to 29

Amazon CloudWatch Metrics made tons of improvements 2 days ago. This release takes advantage of the new metric dimension to increase our validation limit to 29 (MAX-1). By default, we add a service dimension to more easily identify metrics for a given service, hence the limit being 29 and not 30.

Next release

We plan on closing the gap on releases with Lambda Layer versioning by automatically generating documentation for all regions. This means publishing 5 additional regions customers asked for support and making it easier to find out which Lambda Layer has which PyPi version. Beyond that, docs and Event Handler improvements, and maybe a surprise if time allows.

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @heitorlessa, @leandrodamascena, @rubenfonseca, Docs and Release bot

v1.26.7

29 Jul 14:09
160feae

Choose a tag to compare

Summary

This release adds a change to the idempotency utility, expiring in-progress executions if the Lambda function times out halfway through.

The new feature requires no code changes. However, if you're using just the idempotent_function decorator, you will want to register the Lambda context on your handler to take advantage of this feature:

To prevent against extended failed retries when a Lambda function times out, Powertools now calculates and includes the remaining invocation available time as part of the idempotency record. If a second invocation happens after this timestamp, and the record is marked as INPROGRESS, we will execute the invocation again as if it was in the EXPIRED state (e.g, expire_seconds field elapsed).

We also enabled static analysis (mypy) on the new statically typed documentation snippets - big thanks to @VictorCovalski for spotting one issue in Event Handler that later led to 50 other fixes.

Oh! Did I also tell you we’ve got a new full time maintainer? Big welcome to Ruben 😉 https://twitter.com/rubenfonseca

Changes

🌟New features and non-breaking changes

  • feat(idempotency): handle lambda timeout scenarios for INPROGRESS records (#1387) by @rubenfonseca

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(event_handlers): ImportError when importing Response from top-level event_handler (#1388) by @VictorCovalski

🔧 Maintenance

This release was made possible by the following contributors:

@VictorCovalski, @dependabot, @dependabot[bot], @heitorlessa, @rubenfonseca and Release bot

v1.26.6

25 Jul 11:47
7414df7

Choose a tag to compare

Third-time is the luck of the Irish (new security release mechanisms)

Summary

This patch release addresses an internal issue for Event Handler REST API compression feature when headers value is None -- Huge thanks for spotting and fixing it as a first-time contributor @tbuatois!!

We now have public Lambda Layers deployed across all AWS commercial regions (22) - stellar multi-month work by @am29d. We have one last work to complete before we share the additional ARNs with everyone -- automate documentation generation for every Layer Version::Region mapping.

image

Lastly on Operational Excellence, we've implemented further security layers for GitHub Actions following GitHub's Hardening Guide, and created a Maintenance Issue template to make tech debt work more visible to all customers and future maintainers.

Changes

🐛 Bug and hot fixes

  • fix(event_handlers): handle lack of headers when using auto-compression feature (#1325) by @tbuatois

🔧 Maintenance

This release was made possible by the following contributors:

@am29d, @dependabot, @dependabot[bot], @heitorlessa, @tbuatois and Release bot