I have a service with several Python functions in it. Only a couple of them need extra Python packages, so I added a requirements.txt file only for those and set the module for each function.
The problem seems to be that the plugin always expects a requirements file to install for all Python functions so for those that don't have one, it fails with this error:
Error --------------------------------------------------
ENOENT: no such file or directory, open 'requirements.txt'
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: ENOENT: no such file or directory, open 'requirements.txt'
at Object.fs.openSync (fs.js:653:18)
at Object.fs.readFileSync (fs.js:554:33)
at generateRequirementsFile (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:175:6)
at installRequirements (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:41:5)
at values.filter.map.f (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:235:11)
at Array.map (<anonymous>)
at ServerlessPythonRequirements.installAllRequirements (/Users/fede/sls-lambda-project/node_modules/serverless-python-requirements/lib/pip.js:222:8)
From previous event:
at PluginManager.invoke (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/classes/PluginManager.js:372:22)
at PluginManager.run (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/classes/PluginManager.js:403:17)
at variables.populateService.then (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/Serverless.js:102:33)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
at Serverless.run (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/lib/Serverless.js:89:74)
at serverless.init.then (/Users/fede/.nvm/versions/node/v8.5.0/lib/node_modules/serverless/bin/serverless:42:50)
at <anonymous>
Is there a way to omit certain functions? Or am I missing something?
Thanks!
mind sharing your serverless.yml? If I understand the issue it is a bug, the default packaging (not per function) skips with out errors(or at least used to) if no requirements files were found. Per function packaging should do the same. I'll see if I can create some test cases to covers these.
Hi. I think the key part from your answer is "not per function".
I've just tested this yml:
service: requirements-test
provider:
name: aws
runtime: python3.6
package:
individually: true
exclude:
- "**/*"
functions:
func1:
handler: func1/index.handler
module: func1
include:
- function1/index.py
func2:
handler: func2/index.handler
include:
- function2/index.py
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
invalidateCaches: true
dockerizePip: false
If you create those two functions and don't add a requirements.txt at root level and just only one for func1, when you run sls package, the plugin runs correctly for func1 but for func2 gives that error.
位 ~/tmp/requirements-test/ sls package
Serverless: Installing requirements of func1/requirements.txt in .serverless/func1...
Error --------------------------------------------------
ENOENT: no such file or directory, open 'requirements.txt'
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: darwin
Node Version: 8.5.0
Serverless Version: 1.27.3
For the moment, I cant get rid of the error just by adding an empty requirements.txt at root level.
Thanks for the details. That's a :bug:
For now I recommend the workaround you mention of an empty requirements.txt, but I'll fix this in the next release.
Most helpful comment
Thanks for the details. That's a :bug:
For now I recommend the workaround you mention of an empty
requirements.txt, but I'll fix this in the next release.