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
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
Alternative solutions
Acknowledgment