Skip to content

Feature request: Add utility for Lambda Metadata Services #8050

Description

@leandrodamascena

Use case

Lambda has recently launched a metadata device similar to to the Instance Metadata Service that EC2 has. We should add a utility that allows user to access the data without having explicitly make fetch requests to the IP address where the service lives.

Solution/User Experience

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.metadata import LambdaMetadata, get_lambda_metadata, clear_metadata_cache
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}

Alternative solutions

Acknowledgment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Coming soon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions