Hey,
I might be going mad over here, so better ask here:
I have a lambda function foo
that serves a file from the same directory as the function file. Upon deployment the file sometimes seems to live right next to the function Javascript file (whose folder path I can get via process.env.LAMBDA_TASK_ROOT
), sometimes in ./src
, sometimes in ./src/foo
or even ./src/functions/foo
.
I of course used Google and this community to search for other examples, but depending on which post you look at you will see any of the above options (or even more!) suggested. (e.g. https://github.com/netlify/function-deploy-test/blob/master/lambda/zipped-function/zipped-function.js#L6-L8 from @Dennis which suggests ./foo
as the location)
This is one deployment, where src
works:
https://github.com/janpio/netlify-functions-file-foo
https://netlify-functions-image-foo.netlify.app/logo.png
INFO process.env.LAMBDA_TASK_ROOT /var/task
INFO # content of process.env.LAMBDA_TASK_ROOT
INFO [ 'image.js', 'src' ]
INFO # content of process.env.LAMBDA_TASK_ROOT/src
INFO [ 'image.js', 'logo.png' ]
INFO # content of process.env.LAMBDA_TASK_ROOT/src/functions
INFO undefined
INFO # content of process.env.LAMBDA_TASK_ROOT/src/functions/image
INFO undefined
And this is the other deployment with pretty much the same code (same folder structure etc), but totally different folder structure on the deployment:
INFO process.env.LAMBDA_TASK_ROOT /var/task
INFO # content of process.env.LAMBDA_TASK_ROOT
INFO [ 'image.js', 'src' ]
INFO # content of process.env.LAMBDA_TASK_ROOT/src
INFO [ 'functions', 'node_modules' ]
INFO # content of process.env.LAMBDA_TASK_ROOT/src/functions
INFO [ 'image' ]
INFO # content of process.env.LAMBDA_TASK_ROOT/src/functions/image
INFO [ 'image.js', 'logo.png' ]
Locally with netlify dev
the files are directly in process.env.LAMBDA_TASK_ROOT
.
Any idea what is going on here?
I am a bit scared that I am doing something fundamentally wrong or the deployments will change their behavior and break my site