issue with globalIncludes
davidfox-ap opened this issue · 5 comments
I tried to follow the example in the README for using globalIncludes. I uncommented these lines in serverless.yml:
globalIncludes:
- ./common_files
And copied a single file into a new common_files dir:
common_files/s3utilities.py
And left the import statement in my handler script as-is.
When I ran 'serverless deploy' the process exits almost immediately with the error message:
path must be a string or Buffer
Is there anything obvious that I might be doing wrong?
Unrelated to the error, but perhaps of interest, I feel that this structure makes local testing difficult. If I have a script in a folder:
myfunction/handler.py
Which imports a function sitting in common_files, this will not work if I attempt to run handler locally.
Hey @davidfox-ap, Can you share the full error message you're getting and your serverless.yml, please?
Regarding the current structure, can you give more information about the kind of structure that'll make local testing easier?
So, I figured out why this is happening (I think). I was using your plugin because it allowed me to have a custom package zip alongside a set of functions that will be packaged by the plugin. Like so:
customzipfunction:
handler: customzipfunction-handler.customzipfunction
name: ${self:service}-${opt:stage}-customzipfunction
package:
artifact: "./customzipfunction/customzipfunction.zip"
regularfunction:
handler: regularfunction-handler.regularfunction
package:
include:
- regularfunction
artifact: ${self:custom.pkgPyFuncs.buildDir}/${self:service}-${opt:stage}-regularfunction.zip
And this works great! Until I try to use the global files construct:
globalIncludes:
- ./common_files
At this point, unless I remove the custom zip function, I get the following error:
Serverless: [serverless-package-python-functions] Packaging cwfeeder-dev-customzipfunction...
Type Error ---------------------------------------------
path must be a string or Buffer
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 6.11.0
Serverless Version: 1.17.0
I realize I am using the plugin in an unintended fashion. I am only doing it this way, because this particular function has dependencies that quickly exceed the space limitations for a Lambda.
@davidfox-ap Ah, I see what's going wrong.
That error is getting thrown because the plugin expects each function to have a package.include field. I can see that customzipfunction specifies an artifact, but not any includes.
I'll need to think through how to handle this use case in gracefully. Your thoughts on ideal behaviour are welcome.
In the meantime, a quick and dirty workaround that'll let you keep moving forward while a fix for this is being developed is to specify dummy "include" folder for customzipfunction as below:
customzipfunction:
handler: customzipfunction-handler.customzipfunction
name: ${self:service}-${opt:stage}-customzipfunction
package:
include:
- dummyfolder # <---- Dummy folder with dummy content
artifact: "./customzipfunction/customzipfunction.zip"
This will allow the plugin create a 'customzipfunction.zip' in the build directory. But since you're specifying your own customzipfunction.zip file, the one created by the plugin will be ignored when the framework deploys, and your custom file will be deployed instead.
I'll work on a clean fix for this and update the plugin when its ready.
Thanks for the catch!
Thanks for the clever workaround - it worked!
@davidfox-ap Just published v0.2.3 to address this issue.
The plugin should no longer throw an error when package.include is not specified, meaning you can get rid of your dummy folder. Please give it a try and let me know if you run into any issues