Hello.
When using node-auth0 v4.3.1 and v3.7.2 in Lambda, there's a 1000ms difference in processing time during Lambda's cold start.
My Lambda function is developed using Node.js v20 + TypeScript + SAM. I've also added node-auth0 to a layer and imported it into my Lambda function.
Here are the Lambda function and layer codes for both v4.3.1 and v3.7.2.
Although it's simple code using node-auth0 and X-Ray (for measuring processing time), when executing the Lambda function, the processing time for the v4.3.1 function is 1000ms slower. Why is this?
I've managed to achieve the same processing time as v3.7.2 by increasing the Lambda's memory, but this incurs additional costs. If possible, I'd like to reduce the cost while maintaining the same processing time as v3.7.2.
Thanks.
v.4.3.1
lambda code
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { AWSXRay } from '/opt/nodejs/lib/x-ray';
import { getUsersByEmail } from '/opt/nodejs/lib/auth0';
export const lambdaHandler = async (
event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
const segment = AWSXRay.getSegment();
if (!segment) {
const error = new Error('segment is undefined');
console.error(error);
throw error;
}
const getUserByEmailSegment = segment.addNewSubsegment('getUserByEmail');
let users;
try {
const email = JSON.parse(event.body!).email;
if (!email) {
const error = new Error('email is not found');
console.error(error);
throw error;
}
users = await getUsersByEmail(email);
} catch (error: any) {
return {
statusCode: 500,
body: JSON.stringify(error),
};
} finally {
getUserByEmailSegment.close();
}
segment.close();
return {
statusCode: 200,
body: JSON.stringify(users),
}
};
Checklist
Description
Hello. When using node-auth0 v4.3.1 and v3.7.2 in Lambda, there's a 1000ms difference in processing time during Lambda's cold start. My Lambda function is developed using Node.js v20 + TypeScript + SAM. I've also added node-auth0 to a layer and imported it into my Lambda function.
Here are the Lambda function and layer codes for both v4.3.1 and v3.7.2. Although it's simple code using node-auth0 and X-Ray (for measuring processing time), when executing the Lambda function, the processing time for the v4.3.1 function is 1000ms slower. Why is this? I've managed to achieve the same processing time as v3.7.2 by increasing the Lambda's memory, but this incurs additional costs. If possible, I'd like to reduce the cost while maintaining the same processing time as v3.7.2.
Thanks.
v.4.3.1
lambda code
layer code
v3.7.2
lambda code
layer code
Reproduction
Additional context
Processing time for v4.3.1 as measured by X-Ray
The getUserByEmail process takes 2040ms
Processing time for v3.7.2 as measured by X-Ray
The getUserByEmail process takes 1010ms
node-auth0 version
4.3.1 and 3.7.2
Node.js version
nodejs20.x(lambda)