-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(clients): support recursion detection in Lambda #3654
Conversation
const recursionDetectionMiddleware = (options: PreviouslyResolved): BuildMiddleware<any, any> => | ||
(next: BuildHandler<any, Output>): BuildHandler<any, Output> => | ||
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => { | ||
const { request } = args; | ||
if ( | ||
!HttpRequest.isInstance(request) || | ||
options.runtime !== "node" || | ||
request.headers.hasOwnProperty(TRACE_ID_HEADER_NAME) | ||
) { | ||
return next(args); | ||
} | ||
|
||
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME]; | ||
const traceId = process.env[ENV_TRACE_ID]; | ||
const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0; | ||
if (nonEmptyString(functionName) && nonEmptyString(traceId)) { | ||
request.headers[TRACE_ID_HEADER_NAME] = traceId; | ||
} | ||
return next({ | ||
...args, | ||
request, | ||
}); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove additional semicolon and update formatting
const recursionDetectionMiddleware = (options: PreviouslyResolved): BuildMiddleware<any, any> => | |
(next: BuildHandler<any, Output>): BuildHandler<any, Output> => | |
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => { | |
const { request } = args; | |
if ( | |
!HttpRequest.isInstance(request) || | |
options.runtime !== "node" || | |
request.headers.hasOwnProperty(TRACE_ID_HEADER_NAME) | |
) { | |
return next(args); | |
} | |
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME]; | |
const traceId = process.env[ENV_TRACE_ID]; | |
const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0; | |
if (nonEmptyString(functionName) && nonEmptyString(traceId)) { | |
request.headers[TRACE_ID_HEADER_NAME] = traceId; | |
} | |
return next({ | |
...args, | |
request, | |
}); | |
}; | |
} | |
const recursionDetectionMiddleware = | |
(options: PreviouslyResolved): BuildMiddleware<any, any> => | |
(next: BuildHandler<any, Output>): BuildHandler<any, Output> => | |
async (args: BuildHandlerArguments<any>): Promise<BuildHandlerOutput<Output>> => { | |
const { request } = args; | |
if ( | |
!HttpRequest.isInstance(request) || | |
options.runtime !== "node" || | |
request.headers.hasOwnProperty(TRACE_ID_HEADER_NAME) | |
) { | |
return next(args); | |
} | |
const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME]; | |
const traceId = process.env[ENV_TRACE_ID]; | |
const nonEmptyString = (str: unknown): str is string => typeof str === "string" && str.length > 0; | |
if (nonEmptyString(functionName) && nonEmptyString(traceId)) { | |
request.headers[TRACE_ID_HEADER_NAME] = traceId; | |
} | |
return next({ | |
...args, | |
request, | |
}); | |
}; |
The CodeBuild test failed because of transient issue in the last size benchmarking. The rest tests succeeded |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Ref JS-3324
Description
Injects a trace id header in Lambda runtime to avoid recursive invocation.
Testing
Unit test
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.