pypi aws-lambda-powertools 3.38.0
v3.38.0

5 hours ago

Summary

This release adds support for the new Amazon EventBridge Custom Event Bus in Data Classes and Parser, and fixes twenty bugs across Parameters, Event Handler, Idempotency, Logger, Data Classes and Parser.

Almost every fix here came from the community. We opened the bugs we found as good first issue and people picked them up faster than we could review them. Thank you, this is the best part of the job.

Welcome to our thirteen new contributors: @Thanatos9404, @SumiRann1, @proton0210, @azmi2409, @mayuriphad, @MTirnova, @hiyouwhatsapp, @MrNK2107, @sebxt, @codewithzubair07, @Oakcube4life, @Asymtode712 and @alphasafal. Thanks also to @LuisFigueroaG for coming back with another fix.

EventBridge Custom Event Bus

Docs

AWS launched a new EventBridge bus, the Custom Event Bus, with subscribers instead of rules, event retention, ordered delivery per event group, replay, and a PutRawEvents API for Avro, Protobuf and raw bytes. The classic bus is still there, now called Custom Event Bus - Classic.

The new bus delivers events to Lambda in a different shape: a JSON array by default, and a Data / Metadata / SystemMetadata envelope when the subscriber uses the WITH_METADATA transformer. The existing EventBridgeEvent data class and EventBridgeModel only understand the classic single envelope, so we added new ones.

EventBridgeV2Event accepts a single object or an array, with or without metadata, and always exposes a list of records:

from aws_lambda_powertools.utilities.data_classes import EventBridgeV2Event, event_source


@event_source(data_class=EventBridgeV2Event)
def lambda_handler(event: EventBridgeV2Event, context):
    for record in event.records:
        if record.system_metadata.delivery_type == "REPLAY":
            continue
        process(record.detail or record.data)

Two things to know before you migrate to EventBridgeV2. The Lambda runtime's bundled boto3 does not have the eventbridgev2 client yet, so publishing to the new bus from inside a function requires packaging boto3 1.43.102 or newer. And we have not added BatchProcessor support for this bus yet: in our tests a partial batch response was not applied by the service, so for now treat each delivery as all-or-nothing and raise if any record should be retried. Thank you @Asymtode712 for the implementation and @alphasafal for the octet-stream fix that followed.

Parameters

Nine fixes in Parameters, most of them around get_parameters_by_name and caching:

  • The cache key now includes the SDK options, so get("/x") and get("/x", decrypt=True) no longer return each other's value.
  • get_parameters_by_name supports version and label selectors ("/param:3", "/param:prod"), no longer mutates the dictionary you pass in, and raises GetParameterError when GetParameters fails in fail-fast mode.
  • get_secrets_by_name returns only the names you asked for, instead of every secret sharing the prefix.
  • The AppConfig provider recovers when a poll token is rejected, and the module-level get_app_config keeps one provider per environment and application instead of returning the first one for every call.

Event Handler

  • The HTTP API resolver strips the stage from the path only when it is actually there, so custom domains work again.
  • Catch-all exception handlers no longer turn a 404 into a 500, and exception handlers can return plain values.
  • Multipart and JSON body validation reject malformed bodies with 422 instead of crashing.
  • Regex strip_prefixes strip only a leading match, Accept-Encoding: gzip;q=0 disables compression, bytes bodies with a JSON content type are base64 encoded, content-type is matched in any casing, and responses echoing a specific origin carry Vary: Origin.

Other fixes

  • Idempotency: CachePersistenceLayer reads the expiry from the configured expiry_attr and no longer emits the Redis deprecation warning when you use the new name.
  • Logger: use_datetime_directive with %F no longer adds milliseconds twice.
  • Data Classes and Parser: VPC Lattice v2 x509 identity fields are read with the casing AWS actually sends.

Changes

  • fix(parser): pass non-JSON octet-stream payloads to the model in EventBridgeV2Envelope (#8669) by @alphasafal
  • fix(event_handler): fix prefix stripping, gzip negotiation, JSON detection and CORS Vary (#8638) by @Oakcube4life
  • fix(data-classes,parser): read VPC Lattice v2 x509 identity fields with the casing AWS sends (#8628) by @LuisFigueroaG
  • fix(logger): stop adding milliseconds twice when use_datetime_directive is set (#8632) by @sebxt
  • fix(parameters): recover AppConfig sessions after rejected poll tokens (#8615) by @proton0210
  • fix(parameters): key appconfig default provider by environment and ap… (#8635) by @codewithzubair07
  • fix(parameters): return only requested secret names (#8621) by @hiyouwhatsapp
  • fix(parameters): support version and label selectors in get_parameters_by_name (#8620) by @MTirnova
  • fix(parameters): include sdk_options in the cache key (#8619) by @mayuriphad
  • fix(parameters): raise GetParameterError when GetParameters fails in fail-fast mode (#8616) by @azmi2409
  • fix(parameters): avoid mutating caller's dict in get_parameters_by_name (#8607) by @SumiRann1
  • fix(idempotency): stop CachePersistenceLayer from emitting the Redis deprecation warning (#8625) by @MrNK2107
  • fix(idempotency): read expiry from expiry_attr in CachePersistenceLayer (#8606) by @Thanatos9404
  • fix(event_handler): harden multipart and JSON body validation (#8626) by @MTirnova
  • fix(event_handler): keep catch-all exception handlers off 404s and adapt exception handler returns (#8624) by @MrNK2107
  • fix(event_handler): strip the HTTP API stage only when rawPath has it (#8605) by @Thanatos9404

📜 Documentation updates

  • chore(deps): bump pydantic, aws-cdk, sentry-sdk, pytest-mock, ruff, zensical and GitHub Actions (#8685) by @leandrodamascena
  • feat(data_classes,parser): add EventBridge Custom Event Bus support (#8658) by @Asymtode712

🔧 Maintenance

This release was made possible by the following contributors:

@alphasafal, @Asymtode712, @azmi2409, @codewithzubair07, @hiyouwhatsapp, @leandrodamascena, @LuisFigueroaG, @mayuriphad, @MrNK2107, @MTirnova, @Oakcube4life, @proton0210, @sebxt, @SumiRann1, @Thanatos9404, @dependabot[bot] and codewithzubair07

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

NewReleases is sending notifications on new releases.