Skip to content

v1.24.0

Compare
Choose a tag to compare
@release-drafter release-drafter released this 31 Dec 17:51
· 2706 commits to develop since this release
22f8719

Summary

For the last release of the year (happy 2022!), we bring a major enhancements to Idempotency and Feature Flags.

We also addresses important papercuts like caching parsed JSON data in Event Sources, support for datetime format codes in Logger and the ability to ignore certain endpoints from being traced.

Did I say that 90% of this release was contributed by the community? thank you everyone!!!

HUGE shoutout to @DanyC97 on helping us make all of our documentation banners (warning, tip) consistent.

Big thanks to new contributors too (you rock!)

  • @trey-rosius for adding a medium-size GraphQL API example using a myriad of Lambda Powertools features
  • @nayaverdier for a future proof change on how we internally convert string to bool (distutils being deprecated in Python 3.12)

idempotent_function now supports dataclasses & Pydantic models

Docs with samples

When using idempotent_function to make any Python synchronous function idempotent, you might have data available as Dataclasses or Pydantic models, not just dictionaries.

This release gives you more flexibility on what data can be used as your idempotency token - it could be an entire Dataclass, Pydantic model, or fields within these models.

image

Going beyond boolean feature flags

Docs with sample

You can now use the new boolean_feature: false parameter in your schema to signal Feature Flags that you will return any JSON valid value.

Example scenario: you might have a list of features to unlock for premium customers, or a set of beta features for select customers

{
    "premium_features": {
        "boolean_type": false,
        "default": [],
        "rules": {
            "customer tier equals premium": {
                "when_match": ["no_ads", "no_limits", "chat"],
                "conditions": [
                    {
                        "action": "EQUALS",
                        "key": "tier",
                        "value": "premium"
                    }
                ]
            }
        }
    }
}

Translating to the following API:

from aws_lambda_powertools.utilities.feature_flags import FeatureFlags, AppConfigStore

app_config = AppConfigStore(
    environment="dev",
    application="product-catalogue",
    name="features"
)

feature_flags = FeatureFlags(store=app_config)

def lambda_handler(event, context):
    # Get customer's tier from incoming request
    ctx = { "tier": event.get("tier", "standard") }

    # Evaluate `has_premium_features` base don customer's tier
    premium_features: list[str] = feature_flags.evaluate(name="premium_features",
                                                        context=ctx, default=False)
    for feature in premium_features:
        # enable premium features
        ...

Ignoring HTTP endpoints from tracer

AWS X-Ray has a limit of 64K tracing data. This could be a problem if you're making hundreds of HTTP requests to the same endpoint.

Alternatively, there are sensitive endpoints you might want them to not be included in your tracing data.

You can now use ignore_endpoint for this purpose - globs (*) are allowed!

from aws_lambda_powertools import Tracer

tracer = Tracer()
# ignore all calls to `ec2.amazon.com`
tracer.ignore_endpoint(hostname="ec2.amazon.com")
# ignore calls to `*.sensitive.com/password` and  `*.sensitive.com/credit-card`
tracer.ignore_endpoint(hostname="*.sensitive.com", urls=["/password", "/credit-card"])


def ec2_api_calls():
    return "suppress_api_responses"

@tracer.capture_lambda_handler
def handler(event, context):
    for x in long_list:
        ec2_api_calls()

Changes

🌟New features and non-breaking changes

  • feat(logger): support use_datetime_directive for timestamps (#920) by @huonw
  • feat(feature_flags): support beyond boolean values (JSON values) (#804) by @ran-isenberg
  • feat(idempotency): support dataclasses & pydantic models payloads (#908) by @michaelbrewer
  • feat(tracer): ignore tracing for certain hostname(s) or url(s) (#910) by @michaelbrewer
  • feat(event-sources): cache parsed json in data class (#909) by @michaelbrewer

📜 Documentation updates

  • docs(tracer): new ignore_endpoint feature (#931) by @heitorlessa
  • feat(logger): support use_datetime_directive for timestamps (#920) by @huonw
  • feat(feature_flags): support beyond boolean values (JSON values) (#804) by @ran-isenberg
  • docs(general): consistency around admonitions and snippets (#919) by @DanyC97
  • docs(homepage): new GraphQL sample API in examples section (#930) by @trey-rosius
  • feat(idempotency): support dataclasses & pydantic models payloads (#908) by @michaelbrewer

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@DanyC97, @dependabot, @dependabot[bot], @heitorlessa, @huonw, @michaelbrewer, @nayaverdier, @ran-isenberg and @trey-rosius

New Contributors

Full Changelog: v1.23.0...v1.23.1