Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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) {
Comment thread
darklight3it marked this conversation as resolved.
throw new PlatformError("LAMBDA_TASK_ROOT environment variable is not set");
}

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