serverless-python-requirements icon indicating copy to clipboard operation
serverless-python-requirements copied to clipboard

Packaging just layer with python requirements fails

Open endeepak opened this issue 7 years ago • 15 comments

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

endeepak avatar Apr 08 '19 02:04 endeepak

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

arafatheds avatar May 23 '19 11:05 arafatheds

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

franz101 avatar Jun 04 '19 22:06 franz101

I'm getting the same error

darleisantossoares avatar Jun 14 '19 14:06 darleisantossoares

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

darleisantossoares avatar Jun 15 '19 00:06 darleisantossoares

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

akats avatar Jun 19 '19 18:06 akats

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

ed-sparkes avatar Jul 18 '19 07:07 ed-sparkes

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.

smauermann avatar Aug 09 '19 16:08 smauermann

@endeepak did you solve this issue?

dobeerman avatar Sep 11 '19 19:09 dobeerman

+1

neotheicebird avatar Oct 10 '19 07:10 neotheicebird

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

fireproofsocks avatar Nov 05 '19 19:11 fireproofsocks

This won't deploy if you have:

plugins:
- serverless-python-requirements

but no "function" section or lambda function resource.

svnv-svsv-jm avatar Nov 08 '19 10:11 svnv-svsv-jm

This won't deploy if you have:

plugins:
- serverless-python-requirements

but no "function" section or lambda function resource.

Thanks

zagronitay avatar Nov 12 '19 15:11 zagronitay

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.

jeffwasher avatar Jan 28 '20 12:01 jeffwasher

Looks like there’s some decent workarounds and directives here, closing!

miketheman avatar Feb 20 '20 07:02 miketheman

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.

eltang avatar Jul 27 '20 01:07 eltang