github aws-powertools/powertools-lambda-python v2.2.0

latest releases: v2.43.1, v2.43.0, v2.42.0...
22 months ago

Summary

This release features: (1) a new get_parameters_by_name function to fetch multiple Parameter Store parameters from distinct paths, and (2) a new EphemeralMetrics class for multi-tenancy and ISV use cases that require multiple metrics namespace.

hero image

Fetching distinct parameters by name

Docs

You can now fetch distinct parameters by their full name with get_parameters_by_name.

Previously, you could only fetch multiple parameters by path via get_parameters. We also heard from customers they'd like more flexibility when fetching parameters.

This new high level function has the following in mind:

  • Per parameter config: cache parameters differently while fetching them in batch
  • Decrypt all, none, or a few: transparent batch operations for when decryption is required without being worried on aggressive throttling
  • Fail-fast vs graceful error handling: choose whether to fail at the error, or aggregate errors so you can handle them gracefully

Quick flow on how get_parameters_by_name decides which System Manager Parameter Store to use based on per parameter config (or global):

                           ┌────────────────────────┐
                       ┌───▶  Decrypt entire batch  │─────┐
                       │   └────────────────────────┘     │     ┌────────────────────┐
                       │                                  ├─────▶ GetParameters API  │
┌──────────────────┐   │   ┌────────────────────────┐     │     └────────────────────┘
│   Split batch    │───┼──▶│ No decryption required │─────┘
└──────────────────┘   │   └────────────────────────┘
                       │                                        ┌────────────────────┐
                       │   ┌────────────────────────┐           │  GetParameter API  │
                       └──▶│Decrypt some but not all│──────────▶├────────────────────┤
                           └────────────────────────┘           │ GetParameters API  │
                                                                └────────────────────┘

EphemeralMetrics

Docs

You can use EphemeralMetrics class when looking to isolate multiple instances of metrics with distinct namespaces and/or dimensions.

from aws_lambda_powertools.metrics import EphemeralMetrics, MetricUnit
from aws_lambda_powertools.utilities.typing import LambdaContext

metrics = EphemeralMetrics()


@metrics.log_metrics
def lambda_handler(event: dict, context: LambdaContext):
    metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)

By default, Metrics share metrics data across instances. This prevents common data deduplication due to CloudWatch EMF constraints on metric dimensions. However, this limits use cases where you want to create metrics for different applications within the same Lambda function, namely multi-tenancy - whether you use distinct metrics dimensions per metric or multiple metric namespaces.

There are subtle differences between the two:

Feature Metrics EphemeralMetrics
Share data across instances (metrics, dimensions, metadata, etc.) Yes -
Default dimensions that persists across Lambda invocations (metric flush) Yes -

Changes

🌟New features and non-breaking changes

  • feat(parameters): add get_parameters_by_name for SSM params in distinct paths (#1678) by @heitorlessa
  • feat(metrics): add EphemeralMetrics as a non-singleton option (#1676) by @heitorlessa

📜 Documentation updates

  • feat(parameters): add get_parameters_by_name for SSM params in distinct paths (#1678) by @heitorlessa
  • feat(metrics): add EphemeralMetrics as a non-singleton option (#1676) by @heitorlessa

🔧 Maintenance

  • chore(deps-dev): bump aws-cdk-lib from 2.49.0 to 2.50.0 (#1683) by @dependabot
  • feat(parameters): add get_parameters_by_name for SSM params in distinct paths (#1678) by @heitorlessa
  • chore(deps-dev): bump mypy-boto3-dynamodb from 1.25.0 to 1.26.0.post1 (#1682) by @dependabot
  • chore(deps-dev): bump mypy-boto3-cloudformation from 1.25.0 to 1.26.0.post1 (#1679) by @dependabot

This release was made possible by the following contributors:

@dependabot, @dependabot[bot], @heitorlessa, Release bot

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

NewReleases is sending notifications on new releases.