Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/utils/runtime-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/utils/runtime-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,9 +33,6 @@ export async function createRuntime(
if (!handlerString) {
throw new PlatformError("_HANDLER environment variable is not set");
}
if (!taskRoot) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still check that it's not empty

@darklight3it darklight3it Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I was super undecided for this.

You are right to be suspicious. However, I don't know if process.cwd() could ever be undefined or even string.empty, by definition a process should start somewhere on the filesystem.

And on the practical side the result would be the same as putting the handler in the wrong folder.

https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/9ab0fac53c768d6d8901dca9788c729d8eba94ec/src/function/module-loader.ts

https://nodejs.org/api/process.html#processcwd

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.cwd() would never be empty isn't it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.cwd() would never be empty isn't it?

exactly

throw new PlatformError("LAMBDA_TASK_ROOT environment variable is not set");
}

const rapidClient = await RAPIDClient.create(
runtimeApi,
Expand Down
Loading