Skip to content

Releases: aws-powertools/powertools-lambda-python

v3.17.0

15 Jul 08:47
Compare
Choose a tag to compare

Summary

This release enhances the Parser experience with new schemas for Amazon Cognito User Pool triggers. We also added support for externalDocs parameter in our OpenAPI utility.

⭐️ Thanks to @VatsalGoel3 for working on all the new schemas added in this release, as well as @mhindery and @kimsappi for their first contributions!

New Cognito Trigger Schemas

Docs

You can now use one of the new built-in schemas from Parser to easily work with events coming from Amazon Cognito to your Lambda function. With Amazon Cognito User Pools, you can configure triggers to invoke AWS Lambda functions, modifying the authentication behavior.

Below is a list of schemas we’ve added:

  • CognitoCreateAuthChallengeTriggerModel
  • CognitoCustomEmailSenderTriggerModel
  • CognitoCustomMessageTriggerModel
  • CognitoCustomSMSSenderTriggerModel
  • CognitoDefineAuthChallengeTriggerModel
  • CognitoMigrateUserTriggerModel
  • CognitoPostAuthenticationTriggerModel
  • CognitoPostConfirmationTriggerModel
  • CognitoPreAuthenticationTriggerModel
  • CognitoPreSignupTriggerModel
  • CognitoPreTokenGenerationTriggerModelV1
  • CognitoPreTokenGenerationTriggerModelV2AndV3
  • CognitoVerifyAuthChallengeTriggerModel

For more information, refer to the Amazon Cognito User Pools documentation.

Changes

🌟New features and non-breaking changes

  • feat(parser): Added Cognito trigger schemas (#6737) by @VatsalGoel3
  • feat(event_handler): add support for externalDocs attribute in OpenAPI schema (#6945) by @mhindery

📜 Documentation updates

🐛 Bug and hot fixes

  • fix: enable response compression when using multi-value headers (#6936) by @kimsappi

🔧 Maintenance

This release was made possible by the following contributors:

@VatsalGoel3, @dependabot[bot], @dreamorosi, @github-actions[bot], @kimsappi, @leandrodamascena, @mhindery, @ran-isenberg, dependabot[bot] and github-actions[bot]

v3.16.0

04 Jul 12:46
Compare
Choose a tag to compare

Summary

We are thrilled to announce that Powertools for AWS Lambda (Python) now offers AWS Lambda layers in the AWS China region cn-north-1.

New AWS China Lambda Layer ARNs

You can now use Powertools for AWS Lambda (Python) Lambda layers in the AWS China regions, enhancing customer experience by making our pre-packaged Lambda layers available in this AWS partition.

To take advantage of the new layers, you need to update your functions or deployment setup to include one of the new Lambda layer ARN from the table below:

AWS China (cn-north-1)

Architecture Layer ARN
x86_64 arn:aws-cn:lambda:cn-north-1:498634801083:layer:AWSLambdaPowertoolsPythonV3-{python_version}-x86_64:{version}
ARM arn:aws-cn:lambda:cn-north-1:498634801083:layer:AWSLambdaPowertoolsPythonV3-{python_version}-arm64:{version}

Changes

🌟New features and non-breaking changes

  • feat(ci): Partition workflow scripts updated to work (#6900) by @sthulb
  • feat(ci): Deploy to AWS China partitions (#6867) by @sthulb

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@amin-farjadi, @dependabot[bot], @dreamorosi, @github-actions[bot], @kimsappi, @leandrodamascena, @sthulb, @tonnico, dependabot[bot] and github-actions[bot]

v3.15.1

02 Jul 09:43
Compare
Choose a tag to compare

Summary

In this release we fixed a problem when deserializing protobuf records with complex schemas.

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@leandrodamascena

v3.15.0

20 Jun 16:27
Compare
Choose a tag to compare

Summary

We're excited to announce the Kafka Consumer utility, which transparently handles message deserialization, provides an intuitive developer experience, and integrates seamlessly with the rest of the Powertools for AWS Lambda ecosystem.

Key features

  • Automatic deserialization of Kafka messages (JSON, Avro, and Protocol Buffers)
  • Simplified event record handling with intuitive interface
  • Support for key and value deserialization
  • Support for Pydantic models and Dataclass output
  • Support for Event Source Mapping (ESM) with and without Schema Registry integration
  • Out of the box error handling for deserialization issues

Getting Started

To get started, depending on the schema types you want to use, install the library and the corresponding libraries:

For JSON schemas:

pip install aws-lambda-powertools

For Avro schemas:

pip install 'aws-lambda-powertools[kafka-consumer-avro]'

For Protobuf schemas:

pip install 'aws-lambda-powertools[kafka-consumer-protobuf]'

Additionally, if you want to use output serialization with Pydantic Models or Dataclases

Processing Kafka events

Docs

You can use Kafka consumer utility to transform raw Kafka events into an intuitive format for processing.

The @kafka_consumer decorator can deserialize both keys and values independently based on your schema configuration. This flexibility allows you to work with different data formats in the same message.

Working with Avro
carbon (8)

Working with Protobuf
carbon (9)

Working with JSON
carbon (10)

Custom output serializers

Docs

You can transform deserialized data into your preferred object types using output serializers. This can help you integrate Kafka data with your domain models and application architecture, providing type hints, validation, and structured data access.

carbon (11)

Error handling

Docs

You can handle errors when processing Kafka messages to ensure your application maintains resilience and provides clear diagnostic information.

We lazily decode fields like value, key, and headers only when accessed. This allows you to handle deserialization errors at the point of access rather than when the record is first processed.

carbon (12)

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

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

v3.14.0

04 Jun 08:28
Compare
Choose a tag to compare

Summary

This release introduces a new BedrockAgentFunctionResolver to Event Handler that simplifies connecting AWS Lambda functions to Amazon Bedrock Agents. This feature eliminates the need to write boilerplate code for parsing requests and formatting responses, allowing you to focus on your agent's business logic.

We would also like to extend a huge thank you to our new contributor @LucasCMFBraga

Creating Amazon Bedrock Agents

Docs

You can now use the new BedrockAgentFunctionResolver to register tools and handle requests in your Lambda functions. The resolver will automatically parse the request, route it to the appropriate function, and return a well-formed response that includes the tool's output and any existing session attributes.

bedrock_agent1

By default, errors are handled gracefully and returned to the agent with error type and message information, allowing the conversation to continue. This is useful when you want to let the LLM handle errors and reduce boilerplate error-handling code.

If you need more control over error scenarios, you can use BedrockFunctionResponse to customize the response and determine if the conversation should continue:

bedrock_error_response

You can also use the BedrockFunctionResponse when you want to enrich the response with session attributes or knowledge base configurations, or when you want the agent to re-prompt the user to provide additional information.

Changes

🌟New features and non-breaking changes

  • feat(bedrock_agent): add new Amazon Bedrock Agents Functions Resolver (#6564) by @anafalcao
  • feat(event_handler): enable support for custom deserializer to parse the request body (#6601) by @LucasCMFBraga

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@LucasCMFBraga, @anafalcao, @dependabot[bot], @github-actions[bot], @hjgraca, @leandrodamascena, dependabot[bot] and github-actions[bot]

v3.13.0

20 May 10:31
Compare
Choose a tag to compare

Summary

In this release, we renamed the Redis class to Cache in our Idempotency utility and added support for the valkey-glide library.

Thanks to our new contributors @AlisonVilela, @Artur-T-Malas, and @kiitosu, we also fixed bugs in our Event Source Data Class utility. ⭐🏅

Working with the new CachePersistenceLayer class

Docs

You can now use our CachePersistenceLayer classes, which are more generically named, in place of the previous Redis-specific classes when using the Idempotency feature.

For backward compatibility, we've maintained the old Redis class names. However, these are now marked as deprecated and will be removed in the next major version.

We've also added support for valkey-glide, providing more flexibility for your caching implementation needs.

glide

If you are using the RedisPersistenceLayer class in your codebase, you can use the new CachePersistenceLayer as a drop-in replacement.

Changes

🌟New features and non-breaking changes

  • feat(parser): add support to decompress Kinesis CloudWatch logs in Kinesis envelope (#6656) by @Artur-T-Malas
  • feat(event_source): add support for tumbling windows in Kinesis and DynamoDB events (#6658) by @kiitosu
  • feat(event_source): export SQSRecord in data_classes module (#6639) by @AlisonVilela

🔧 Maintenance

This release was made possible by the following contributors:

@AlisonVilela, @Artur-T-Malas, @dependabot[bot], @github-actions[bot], @kiitosu, @leandrodamascena, dependabot[bot] and github-actions[bot]

v3.12.0

06 May 10:10
Compare
Choose a tag to compare

Summary

Thanks to @anafalcao, in this release we added support for additional response fields supported by Bedrock Agents when using the BedrockAgentResolver.

Additional response fields with BedrockAgentResolver

Docs

You can use the BedrockResponse class to add additional fields as needed, such as session attributes, prompt session attributes, and knowledge base configurations. These fields are useful when you want to persist attributes across multiple sessions, for example

bedrock_response

Changes

🌟New features and non-breaking changes

  • feat(bedrock_agents): add optional fields to response payload (#6336) by @anafalcao

📜 Documentation updates

🔧 Maintenance

This release was made possible by the following contributors:

@anafalcao, @dependabot[bot], @dreamorosi, @github-actions[bot], @leandrodamascena, @ran-isenberg, dependabot[bot] and github-actions[bot]

v3.11.0

25 Apr 15:27
Compare
Choose a tag to compare

Summary

We are excited to announce a new integration for Event Handler to work with AWS AppSync Events APIs. This utility provides a structured way to handle AppSync real-time events through dedicated handler methods, automatic routing, and flexible configuration options.

Our Event Handler REST API now supports customizable HTTP error codes per route. Thanks for this contribution @amin-farjadi.

Additionally, our Data masking utility now supports a broader range of types including Pydantic models, dataclasses, and standard Python classes - an outstanding contribution from @VatsalGoel3.

⭐ Huge thanks to @GuidoNebiolo, @kazu728, @victorperezpiqueras, and @konokenj for their contributions in this release.

New Event Handler for AppSync Events feature

Docs

The new AppSyncEventsResolver is designed to streamline working with AWS AppSync real-time APIs by:

  • Handling publish and subscribe events with dedicated handler methods
  • Routing events automatically based on namespace and channel patterns
  • Supporting wildcard patterns for catch-all handlers
  • Processing events in parallel (async) or sequentially
  • Controlling event aggregation for batch processing
  • Implementing graceful error handling

Working with publish events

You can register handlers for publish events using @app.on_publish() to process and validate messages before they're broadcasted to subscribers. This is useful to modify payload content, apply business logic, and reject messages when needed.

publish

Working with subscribe events

You can use @app.on_subscribe() to handle subscription requests before allowing clients to listen to specific channels. This enables authorization checks and subscription filtering based on client context or payload attributes, s well as subscription tracking, for example.

subscribe

Working with aggregated processing

You can use the parameter aggregate=True to process multiple events together as a batch. This is useful when you need to optimize database operations, or want to have full control over how the messages are processed, for example.

aggregate

AppSync Events FAQs

Q: Can I handle different types of events from the same channel?
A: Yes, you can register different handlers for publish and subscribe events on the same channel.

Q: How does handler precedence work with wildcard patterns?
A: More specific patterns take precedence over wildcards. For example, /default/channel1 will be chosen over /default/*, which will be chosen over /*.

Q: What happens when an exception occurs in my handler?
A: With individual processing (aggregate=False), the utility catches exceptions and includes them in the response for the specific event while still processing other events. You can also explicitly raise an UnauthorizedException exception to reject the entire request.

Q: Can I process events asynchronously?
A: Yes, use the @app.async_on_publish() decorator for asynchronous processing of events.

Q: Does the order of async event processing matter?
A: No, AppSync Events doesn't guarantee delivery order. As long as each response includes the original event ID, AppSync processes them correctly regardless of order.

Q: Can I process multiple events as a batch?
A: Yes, set aggregate=True to receive all matching events as a batch in your handler.

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

  • fix(parser): make key attribute optional in Kafka model (#6523) by @Weugene
  • fix(logger): warn customers when the ALC log level is less verbose than log buffer (#6509) by @anafalcao

🔧 Maintenance

Read more

v3.10.0

08 Apr 14:41
Compare
Choose a tag to compare

Summary

This release introduces a new built-in model AppSyncResolverEventModel for the Parser utility, enabling structured parsing and validation of AWS AppSync Resolver events using Pydantic.

It also improves the developer experience when logging with exc_info=True by updating the logic to check if an actual exception exists before adding exception-related keys to the log.

Fixes missing properties for query string parameters in APIGatewayWebSocketEvent class, and the return type of a parameter in TransferFamilyAuthorizerResponse.

⭐ Huge thanks to @VatsalGoel3, @dave-dotnet-overall and @fabien-github!

Built-in model AppSync Resolver for Parser

Docs

Enables structured parsing and validation of AWS AppSync Resolver events using Pydantic. The schema supports fields such as arguments, identity, source, request, info, prev, and stash, covering all standard AppSync resolver context attributes.

image

Changes

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@VatsalGoel3, @dave-dotnet-overall, @dependabot[bot], @fabien-github, @github-actions[bot], @leandrodamascena, dependabot[bot] and github-actions[bot]

v3.9.0

25 Mar 13:44
Compare
Choose a tag to compare

This release improves the OpenAPI utility, letting customers distinguish between request and response validation errors. It also adds support for API Gateway WebSocket in the Event Source Data Class utility.

Thanks to @ericbn, we simplified the Event Source Data Class utility code, making it more readable and easier to maintain.

⭐ A huge thanks to our new contributor: @amin-farjadi.

Working with OpenAPI response validation

Docs

Customers can now customize response validation errors to be clearly identified.

Previously, both request and response validation failures triggered the same RequestValidationError, making debugging difficult. Response validation now raises a specific ResponseValidationError, helping you quickly identify validation issues. This is useful to both detect and handle these types of errors more easily.

validation

Working with API Gateway WebSocket events

Docs

You can now use the APIGatewayWebSocketEvent data class when working with WebSocket API events. This simplifies handling of API Gateway WebSocket events by providing better type completion in IDEs and easy access to event properties.

data_apigw

Changes

  • refactor(data_classes): Add base class with common code (#6297) by @ericbn
  • refactor(data_classes): remove duplicated code (#6288) by @ericbn
  • refactor(data_classes): simplify nested data classes (#6289) by @ericbn
  • refactor(tests): add LambdaContext type in tests (#6214) by @basvandriel

🌟New features and non-breaking changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@ChristophrK, @amin-farjadi, @basvandriel, @dependabot[bot], @ericbn, @github-actions[bot], @leandrodamascena, dependabot[bot] and github-actions[bot]