Skip to content

feat(lmds): Add support for Lambda Metadata Service#2424

Merged
phipag merged 13 commits intomainfrom
feature/lmds
Mar 19, 2026
Merged

feat(lmds): Add support for Lambda Metadata Service#2424
phipag merged 13 commits intomainfrom
feature/lmds

Conversation

@phipag
Copy link
Contributor

@phipag phipag commented Mar 18, 2026

Summary

Adds powertools-lambda-metadata utility. Can be used to query LMDS endpoint on Lambda. Supports:

  • Lambda Managed Instances thread-safety
  • Caching of result
  • Lazy loading on first request
  • SnapStart hooks to invalidate cache on restore
  • GraalVM supported

User experience

public class TriageHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

    private static final Logger logger = LoggerFactory.getLogger(TriageHandler.class);
    private static final Metrics metrics = MetricsFactory.getMetricsInstance();
    private static final LambdaMetadata METADATA = LambdaMetadataClient.get();

    @Logging(logEvent = true)
    @Tracing
    @FlushMetrics(namespace = "TriagingTemplate", service = "triage")
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
        logger.info("Processing triage request");
        logger.info("Metadata", StructuredArguments.entry("metadata", METADATA));
        logger.info("Metadata AZ ID {}", METADATA.getAvailabilityZoneId());
        logger.info("Environment variables", StructuredArguments.entries(System.getenv()));

        // Add custom metric
        metrics.addMetric("TriageRequests", 1, MetricUnit.COUNT);

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");

        String responseBody = """
                {
                    "message": "Hello from Powertools Triaging Template!",
                    "service": "triage",
                    "version": "1.0.0"
                }
                """;

        logger.info("Triage request processed successfully");

        return new APIGatewayProxyResponseEvent()
                .withStatusCode(200)
                .withHeaders(headers)
                .withBody(responseBody);
    }
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@phipag phipag self-assigned this Mar 18, 2026
@sonarqubecloud
Copy link

@phipag
Copy link
Contributor Author

phipag commented Mar 18, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants