Serverless-python-requirements: Packaging just layer with python requirements fails

Created on 8 Apr 2019  Â·  15Comments  Â·  Source: UnitedIncome/serverless-python-requirements

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
question

All 15 comments

Any inputs on this.. I too get the same error..

Same here. I have to pack it. And then copy the file...

I'm getting the same error

In my case, my file serverless.yml didn't have a lambda function, when I added, it worked.

It works in production, but breaks when I deploy to localstack for local testing

I am getting this too, anyone got a solution. I have a mix of node and python functions in my project, pulling my hair out trying to make this work

It works in production, but breaks when I deploy to localstack for local testing

Care to share your config (serverless.yml specifically)? I am struggling too.

@endeepak did you solve this issue?

+1

+1 same issue. The only workaround I've found is to include a throw-away Lambda function in the serverless definition.

This won't deploy if you have:

plugins:
- serverless-python-requirements

but no "function" section or lambda function resource.

This won't deploy if you have:

plugins:
- serverless-python-requirements

but no "function" section or lambda function resource.

Thanks

I've found you don't need the throwaway lambda if you let serverless-plugin-requirements build its own Lambda Layer like so:

custom:
  pythonRequirements:
    layer: true

Then you should be able to reference both the pythonRequirements layer and your layer in your lambdas.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sepulworld picture sepulworld  Â·  5Comments

bsamuel-ui picture bsamuel-ui  Â·  3Comments

amadensor picture amadensor  Â·  3Comments

davegravy picture davegravy  Â·  5Comments

amitm02 picture amitm02  Â·  6Comments