fix(core): repeat a request ID a controller set in every request ID header (#6914)

* fix(core): repeat a request ID a controller set in every request ID header

AwsRequestIdFilter filled the missing request ID headers with a new UUID,
so a Lambda Invoke answered x-amz-request-id with the invocation's ID and
x-amzn-RequestId, which the SDKs read first, with another one. The filter
now reuses the ID already set.

* test(lambda): check the Invoke request ID with the qualifier tests' function fixture
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-10-29 14:53:37 -04:00
1 parent 981b885348
commit d2a5a82ca2
3 files changed
+48 -2

No files matched your search

@@ -21,7 +21,8 @@ import java.util.UUID;
*
* <p>This filter emits all three so that every AWS SDK variant can find the
* header it expects. If a controller already set {@code x-amz-request-id}
* (e.g. Lambda invoke), the existing value is preserved.
* (e.g. Lambda invoke) or {@code x-amzn-RequestId}, that value is preserved and
* repeated in the other headers, so every SDK reads the same ID.
*/
@Provider
public class AwsRequestIdFilter implements ContainerResponseFilter {
@@ -35,7 +36,7 @@ public class AwsRequestIdFilter implements ContainerResponseFilter {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
// Reuse the same ID across all header variants for this response
String requestId = UUID.randomUUID().toString();
String requestId = existingRequestId(headers);
if (!headers.containsKey(AMZ_REQUEST_ID)) {
headers.putSingle(AMZ_REQUEST_ID, requestId);
@@ -47,4 +48,14 @@ public class AwsRequestIdFilter implements ContainerResponseFilter {
headers.putSingle(AMZ_ID_2, requestId);
}
}
private static String existingRequestId(MultivaluedMap<String, Object> headers) {
for (String name : new String[] {AMZ_REQUEST_ID, AMZN_REQUEST_ID}) {
Object value = headers.getFirst(name);
if (value != null) {
return value.toString();
}
}
return UUID.randomUUID().toString();
}
}