Skip to content

v2.10.0

Latest

Choose a tag to compare

@github-actions github-actions released this 23 Mar 10:28
· 35 commits to refs/heads/main since this release
480bb4b

Summary

This release introduces a new Lambda Metadata utility that provides idiomatic access to the Lambda Metadata Endpoint (LMDS), allowing you to retrieve execution environment metadata like Availability Zone ID.

We also added support for SLF4J fluent API key-value pairs in the Logback and ECS encoders, the Logback and ECS encoders now properly serialize addKeyValue() pairs in structured log output.

🌟 Thanks to @cmtjk for contributing for the first time!

✨ Lambda Metadata Utility

Docs

Added a new powertools-lambda-metadata module that provides access to Lambda execution environment metadata from the Lambda Metadata Service (LMDS). The utility exposes a simple static API with automatic caching for the sandbox lifetime, thread-safe concurrent access for Lambda Managed Instances, automatic SnapStart cache invalidation via CRaC, and GraalVM native-image support.

Install:

<dependency>
    <groupId>software.amazon.lambda</groupId>
    <artifactId>powertools-lambda-metadata</artifactId>
    <version>2.10.0</version>
</dependency>

Basic usage:

import software.amazon.lambda.powertools.metadata.LambdaMetadata;
import software.amazon.lambda.powertools.metadata.LambdaMetadataClient;

public class App implements RequestHandler<Object, String> {

    @Override
    public String handleRequest(Object input, Context context) {
        // Fetch metadata (automatically cached after first call)
        LambdaMetadata metadata = LambdaMetadataClient.get();
        String azId = metadata.getAvailabilityZoneId(); // e.g., "use1-az1"

        return "{\"az\": \"" + azId + "\"}";
    }
}

Eager loading at class initialization:

import software.amazon.lambda.powertools.metadata.LambdaMetadata;
import software.amazon.lambda.powertools.metadata.LambdaMetadataClient;

public class App implements RequestHandler<Object, String> {

    // Fetch during cold start (class loading) - cache auto-invalidated on SnapStart restore
    private static final LambdaMetadata METADATA = LambdaMetadataClient.get();

    @Override
    public String handleRequest(Object input, Context context) {
        return "{\"az\": \"" + METADATA.getAvailabilityZoneId() + "\"}";
    }
}

✨ SLF4J Fluent API Key-Value Pairs in Logging

Docs

Key-value pairs added via SLF4J's fluent API (addKeyValue) are now properly serialized in both LambdaJsonEncoder and LambdaEcsEncoder for Logback. Previously, these values were silently ignored.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class App implements RequestHandler<Object, String> {

    private static final Logger LOG = LoggerFactory.getLogger(App.class);

    @Override
    public String handleRequest(Object input, Context context) {
        LOG.atInfo()
           .addKeyValue("orderId", "12345")
           .addKeyValue("customerId", "C-100")
           .setMessage("Processing order")
           .log();

        return "ok";
    }
}

Changes

This release was made possible by the following contributors:

@Attyuttam, @cmtjk, @dependabot[bot], @github-actions[bot], @phipag, dependabot[bot] and github-actions[bot]