Skip to content

3.2.1

Choose a tag to compare

@github-actions github-actions released this 20 Mar 14:10
88ad045

Summary

In this release we added a new Lambda Metadata utility that provides access to the Lambda Metadata Endpoint (LMDS), allowing you to retrieve execution environment metadata like Availability Zone ID. The metadata is automatically cached for the sandbox lifetime with thread-safe access and native AOT support.

What's New

✨ Lambda Metadata Utility

| Docs

Added a new AWS.Lambda.Powertools.Metadata package that provides access to Lambda execution environment metadata from the Lambda Metadata Endpoint (LMDS). The utility exposes a simple static API with automatic caching for the sandbox lifetime, thread-safe concurrent access, and native AOT compatibility via source-generated JSON serialization.

Install:

dotnet add package AWS.Lambda.Powertools.Metadata

Basic usage:

using AWS.Lambda.Powertools.Metadata;

public class Function
{
    public string Handler(object input, ILambdaContext context)
    {
        var azId = LambdaMetadata.AvailabilityZoneId;
        return $"Running in AZ: {azId}";
    }
}

Multi-AZ routing:

using AWS.Lambda.Powertools.Metadata;

public class Function
{
    public async Task<string> Handler(OrderRequest request, ILambdaContext context)
    {
        var endpoint = LambdaMetadata.AvailabilityZoneId switch
        {
            "use1-az1" => "https://service-az1.internal",
            "use1-az2" => "https://service-az2.internal",
            _ => "https://service.internal"
        };

        return await ProcessOrder(request, endpoint);
    }
}

With Powertools Logging:

using AWS.Lambda.Powertools.Logging;
using AWS.Lambda.Powertools.Metadata;

public class Function
{
    public Function()
    {
        Logger.AppendKey("az_id", LambdaMetadata.AvailabilityZoneId);
    }

    [Logging]
    public string Handler(object input, ILambdaContext context)
    {
        Logger.LogInformation("Processing request");
        return "Success";
    }
}

Error handling:

try
{
    var azId = LambdaMetadata.AvailabilityZoneId;
}
catch (LambdaMetadataException ex)
{
    Console.WriteLine($"Failed to get metadata: {ex.Message}");

    if (ex.StatusCode != -1)
        Console.WriteLine($"HTTP Status: {ex.StatusCode}");
}

Changes

🌟New features and non-breaking changes

  • feat(metadata): add Lambda Metadata utility for retrieving execution environment metadata (#1157) by @hjgraca

📜 Documentation updates

  • feat(metadata): add Lambda Metadata utility for retrieving execution environment metadata (#1157) by @hjgraca

🔧 Maintenance

This release was made possible by the following contributors:

@hjgraca