AWS Security ChangesHomeSearch

AWS lambda documentation change

Service: lambda · 2026-06-10 · Documentation low

File: lambda/latest/dg/lambda-managed-instances-java-runtime.md

Summary

Added Java code examples for timeout handling and propagating deadlines to downstream services

Security assessment

The changes demonstrate best practices for graceful timeout handling and preventing hung network calls, but do not address any specific security vulnerability or weakness. This is reliability optimization rather than security remediation.

Diff

diff --git a/lambda/latest/dg/lambda-managed-instances-java-runtime.md b/lambda/latest/dg/lambda-managed-instances-java-runtime.md
index ea8066740..3d799f5c6 100644
--- a//lambda/latest/dg/lambda-managed-instances-java-runtime.md
+++ b//lambda/latest/dg/lambda-managed-instances-java-runtime.md
@@ -135,0 +136,38 @@ If you use virtual threads in your program or create threads during initializati
+**Example: Timeout handling**
+
+Check remaining time before each unit of work and stop processing before the timeout fires. Configure `BUFFER_MS` based on the expected duration of your next chunk of work.
+    
+    
+    private static final int BUFFER_MS = 2000; // Configure based on your next chunk of work
+    
+    public Map<String, Object> handleRequest(Map<String, Object> event, Context context) {
+        for (Object item : (List<Object>) event.get("items")) {
+            if (context.getRemainingTimeInMillis() < BUFFER_MS)
+                return Map.of("statusCode", 206, "body", "Timeout approaching, stopping early");
+            processItem(item);
+        }
+        return Map.of("statusCode", 200, "body", "Done");
+    }
+
+**Example: Propagating deadlines to downstream calls**
+
+When making calls to downstream services, propagate the remaining time as a timeout to avoid hanging on network calls that would outlive your invocation. Use a per-request override on a shared client rather than creating a new client per invocation:
+    
+    
+    import software.amazon.awssdk.services.s3.S3Client;
+    import software.amazon.awssdk.services.s3.model.GetObjectRequest;
+    import java.time.Duration;
+    
+    private static final S3Client s3 = S3Client.create();
+    
+    public String handleRequest(Map<String, Object> event, Context context) {
+        Duration timeout = Duration.ofMillis(Math.max(1000, context.getRemainingTimeInMillis() - 500));
+    
+        GetObjectRequest req = GetObjectRequest.builder()
+            .bucket("my-bucket").key("my-key")
+            .overrideConfiguration(cfg -> cfg.apiCallTimeout(timeout))
+            .build();
+        s3.getObject(req);
+        return "Done";
+    }
+