github aws-powertools/powertools-lambda-python v3.26.0

7 hours ago

Summary

In this release, we are pleased to announce a new utility for interacting with the Lambda Metadata Service, allowing you to easily retrieve information about the Lambda function, such as the Availability Zone ID.

A huge thanks to @acascell, @shaked-lokits, @maxrabin, and @amin-farjadi, for their contributions 🚀🌟

Lambda Metadata Service

Docs

You can now use get_lambda_metadata() function fetch metadata from the AWS Lambda Metadata endpoint, such as the Availability Zone ID. Results are cached for the sandbox lifetime and the utility automatically returns empty metadata outside of Lambda, so your code works seamlessly in local development and testing.

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.metadata import LambdaMetadata, get_lambda_metadata
from aws_lambda_powertools.utilities.typing import LambdaContext

logger = Logger()


def lambda_handler(event: dict, context: LambdaContext) -> dict:
    metadata: LambdaMetadata = get_lambda_metadata()
    az_id = metadata.availability_zone_id  # e.g., "use1-az1"

    logger.append_keys(az_id=az_id)
    logger.info("Processing request")

    return {"az_id": az_id}

Changes

📜 Documentation updates

🐛 Bug and hot fixes

🔧 Maintenance

This release was made possible by the following contributors:

@acascell, @amin-farjadi, @dependabot[bot], @github-actions[bot], @leandrodamascena, @shaked-lokits, dependabot[bot] and github-actions[bot]

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

NewReleases is sending notifications on new releases.