github aws-powertools/powertools-lambda-python v1.15.0

latest releases: v3.2.0, v3.1.0, v3.0.0...
3 years ago

Summary

This release has three major goodies: 1/ Idempotency utility is now GA, 2/ New API Gateway and ALB event handler, and 3/ MANY enhancements to Logger.

Idempotency

Idempotency utility was introduced in 1.11.0 as beta. If you haven't used it yet, it converts Lambda functions into idempotent operations that are safe to retry - This is mostly needed when your code is not idempotent.

Since launch, we've made improvements to error handling and documentation updates. This gives us confidence that the UX won't radically change and therefore can be used safely moving forward.

Idempotency showcase

API Gateway and ALB event handler

huge thanks to @michaelbrewer

This new utility provides a lightweight routing to reduce boilerplate for API Gateway REST/HTTP API and ALB. It also natively integrates with Data classes utility giving you handy methods and self-documented properties of API Gateway and ALB events.

image

It's important to note that this is not a replacement for fully fledged web frameworks like Flask and Djano, or microframeworks like Chalice. Instead, this gives you a nearly zero overhead (~1-2ms) lightweight solution to build applications on top of either API Gateway or ALB.

As a trade-off for being so lightweight, you have to setup infrastructure to use Lambda Proxy Integration using your preferred framework be that CloudFormation, SAM, CDK, Terraform, etc. Rest assured we provide a sample template to demonstrate how you can configure it if you haven't done this yet.

Did I say CORS is simplified too? :)

image

Logger

This release makes Logger more flexible by allowing you to bring your own Logging Formatter and Handler. It also includes a ton of improvements such as:

  • Easily remap keys or bring own defaults by inheriting the now exposed LambdaPowertoolsFormatter
  • UTC support with as simple as utc=True flag
  • Easier methods to add or remove logging keys at runtime with append_keys() and remove_keys(). The previous method, structure_logs(append=True, ...), will continue to work for backwards compatibility and will be effectively when we decide to cut a major version (2.0) - warnings will be place in time too
  • All keys can be reordered including the ones you're going to introduce yet at runtime
  • sampling_rate key only gets added when feature is added
  • Bring your own JSON serializer or deserializer function like the ultra fast Orjson, for when you need to crunch every possible ms
  • timestamp key now includes timezone at the end: from 2021-05-03 11:47:12,494 to 2021-05-03 11:47:12,494+0200

image

API Gateway support for Parser

huge thanks to @risenberg-cyberark

You can now easily parse and run deep data validation with APIGatewayProxyEvent in Parser, including an envelope ApiGatewayEnvelope.

Metrics

Last but not least, you can now set default metric dimensions to ensure these will always be added across all metrics: metrics.set_default_dimensions(environment="prod", another="one")

Changes

🌟New features and non-breaking changes

  • refactor(event-handler): Add ResponseBuilder and more docs (#412) by @michaelbrewer
  • feat(event-handler): add http ProxyEvent handler (#369) by @michaelbrewer
  • feat(metrics): add support to persist default dimensions (#410) by @heitorlessa
  • refactor(logger): BYOFormatter and Handler, UTC support, and more (#404) by @heitorlessa
  • feat(parser): Support for API GW v1 proxy schema & envelope (#403) by @risenberg-cyberark

🌟 Minor Changes

πŸ“œ Documentation updates

πŸ› Bug and hot fixes

Internal

This release was made possible by the following contributors:

@carlos-alberto, @heitorlessa, @michaelbrewer and @risenberg-cyberark

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

NewReleases is sending notifications on new releases.