From 9b9bca369dd04943a7103241c6cb342859b6f43f Mon Sep 17 00:00:00 2001 From: Davide Melfi Date: Fri, 12 Jun 2026 15:51:59 +0100 Subject: [PATCH] fix: defaulting to process.cwd() when LAMBDA_TASK_ROOT is not found --- src/utils/runtime-setup.test.ts | 8 +++++--- src/utils/runtime-setup.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/utils/runtime-setup.test.ts b/src/utils/runtime-setup.test.ts index 24b1a51..84a7c5c 100644 --- a/src/utils/runtime-setup.test.ts +++ b/src/utils/runtime-setup.test.ts @@ -68,13 +68,15 @@ describe("runtime-setup", () => { ); }); - it("should throw if LAMBDA_TASK_ROOT is not set", async () => { + it("should fall back to process.cwd() when LAMBDA_TASK_ROOT is not set", async () => { // GIVEN delete process.env.LAMBDA_TASK_ROOT; // WHEN & THEN - await expect(createRuntime()).rejects.toThrow( - "LAMBDA_TASK_ROOT environment variable is not set", + await createRuntime(); + expect(UserFunctionLoader.load).toHaveBeenCalledWith( + process.cwd(), + expect.any(String), ); }); }); diff --git a/src/utils/runtime-setup.ts b/src/utils/runtime-setup.ts index bf61cdf..6e9f54c 100644 --- a/src/utils/runtime-setup.ts +++ b/src/utils/runtime-setup.ts @@ -18,7 +18,12 @@ export async function createRuntime( const isMultiConcurrent = isMultiConcurrentMode(); const runtimeApi = process.env.AWS_LAMBDA_RUNTIME_API; const handlerString = process.env._HANDLER; - const taskRoot = process.env.LAMBDA_TASK_ROOT; + // LAMBDA_TASK_ROOT is a restricted environment variable set to /var/task. + // If we set it as required we are forcing customers to set it to a value that + // can't change. + // We fall back to process.cwd() to allow OCI customers to place the handler wherever + // they want. + const taskRoot = process.env.LAMBDA_TASK_ROOT || process.cwd(); if (!runtimeApi) { throw new PlatformError( @@ -28,9 +33,6 @@ export async function createRuntime( if (!handlerString) { throw new PlatformError("_HANDLER environment variable is not set"); } - if (!taskRoot) { - throw new PlatformError("LAMBDA_TASK_ROOT environment variable is not set"); - } const rapidClient = await RAPIDClient.create( runtimeApi,