serverless-python-requirements: Packaging just layer with python requirements fails
Code & Config
serverless.yml
service: layer-package-bug
provider:
name: aws
runtime: python2.7
stage: dev
layers:
layer-package-bug:
path: .
name: ${self:provider.stage}-layer-package-bug
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
slim: true
dockerizePip: non-linux
package:
include:
- '*.py'
requirements.txt
dnspython
layer.py
import dns.resolver
def query(domain):
return dns.resolver.query(domain)
Command and Error
➜ layer-package-bug SLS_DEBUG=* sls package
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command requirements
Serverless: Load command requirements:clean
Serverless: Load command requirements:install
Serverless: Load command requirements:cleanCache
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Generated requirements from ~/code/layer-package-bug/requirements.txt in ~/code/layer-package-bug/.serverless/requirements.txt...
Serverless: Installing requirements from ~/code/layer-package-bug/.serverless/requirements/requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python2.7
Serverless: Running docker run --rm -v ~/code/layer-package-bug/.serverless/requirements\:/var/task\:z -u 0 lambci/lambda\:build-python2.7 /bin/sh -c 'python2.7 -m pip install -t /var/task/ -r /var/task/requirements.txt && find /var/task -name \\*.so -exec strip \\{\\} \\;'...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...
Type Error [ E R R_ I N V A L I D_ A R G_ T Y P E] -----
The "path" argument must be one of type string, Buffer, or URL. Received type undefined
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
at readFile (fs.js:301:3)
at go$readFile (~/code/layer-package-bug/node_modules/graceful-fs/graceful-fs.js:85:14)
at Object.readFile (~/code/layer-package-bug/node_modules/graceful-fs/graceful-fs.js:82:12)
at Object.readFile (~/code/layer-package-bug/node_modules/universalify/index.js:5:67)
at injectRequirements (~/code/layer-package-bug/node_modules/serverless-python-requirements/lib/inject.js:23:6)
at ServerlessPythonRequirements.injectAllRequirements (~/code/layer-package-bug/node_modules/serverless-python-requirements/lib/inject.js:120:12)
at ServerlessPythonRequirements.BbPromise.bind.then.then.then (~/code/layer-package-bug/node_modules/serverless-python-requirements/index.js:183:43)
at processImmediate (internal/timers.js:443:21)
at process.topLevelDomainCallback (domain.js:136:23)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
OS: darwin
Node Version: 11.13.0
Serverless Version: 1.40.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 16
- Comments: 15
Looks like there’s some decent workarounds and directives here, closing!
Just to clarify, is there a way to package a set of user-defined modules along with their dependencies into a single layer? If not, I think support for that use case would be nice considering the 5-layer limit for functions.
I’ve found you don’t need the throwaway lambda if you let serverless-plugin-requirements build its own Lambda Layer like so:
Then you should be able to reference both the pythonRequirements layer and your layer in your lambdas.
Thanks
This won’t deploy if you have:
but no “function” section or lambda function resource.