Serverless-python-requirements: Per-function requirements cannot use package include

Created on 9 Apr 2018  ยท  5Comments  ยท  Source: UnitedIncome/serverless-python-requirements

I use per-function requirements
โ”œโ”€โ”€ serverless.yml
โ”œโ”€โ”€ config
โ”‚ โ””โ”€โ”€ settings.py
โ”œโ”€โ”€ function1
โ”‚ โ”œโ”€โ”€ requirements.txt
โ”‚ โ””โ”€โ”€ index.py
โ””โ”€โ”€ function2
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ index.py

serverless.yml is
package:
individually: true

functions:
func1:
handler: index.handler
module: function1
func2:
handler: index.handler
module: function2
package:
include:
- config/**

issuse is : the config/** wouldn't be include in func2. how can didi it

question

All 5 comments

Hmm. I think it'd work if you do:

cd function1
ln -s ../config
cd ../function2
ln -s ../config
cd ..
sls deploy

I agree that's not optimal, but I think it should work. Any input @cgrimal, since you implemented the per-function requirements?

I managed to reproduce the issue indeed. That said, the handling of linking (now injecting) has been completely reworked since i implemented this feature and I don't see where the include directive is supposed to be handled. It might be a bug I'm afraid.

Even though @dschep's workaround should work, you can also use the vendor mechanism. With your exact folder structures, it works with this minimal serverless.yml file:

service: issue_168

provider:
    name: aws
    runtime: python3.6

package:
    individually: true
    include:  # not working :'(
        - config/**

functions:
    func1:
        handler: index.handler
        module: function1
        vendor: ./config
    func2:
        handler: index.handler
        module: function2
        vendor: ./config

plugins:
  - serverless-python-requirements

You can run the sls package -v -f func1 command, and look into the function1.zip artefact created in the .serverless folder.

@dschep @cgrimal thanks, i will use vendor temporary.

Hi @cgrimal, I have a very similar structure to OP (the folder is called common instead of config) and I've tried to use vendor as you suggested but the folder does not get included.

airwitsX3:
  handler: airwitsX3.handler
  module: iot/processing/airwitsX3
  vendor: ./common
  events:
    - stream:
        type: kinesis
        arn: "arn:aws:kinesis:${self:custom.region}:${self.custom.streamID}:stream/${self:custom.streamName}"

I have also tried @dschep's suggestion to put a symlink, this works but it's not possible to use exclude or slimPatterns anymore (I have a few tests in there).
I have tried to have a look in the source code but I'm not familiar with serverless plugin structure and cannot find the point where the vendor key is taken into account.

Is there a way to make either include or vendor work again?
Thanks!

Hi @antoniocaiazzo, I'm afraid I haven't been using (or working on) this project for too long now, and I don't think I can help you. You'll have better chances if you open a new issue (you may still reference this one).

I hope you'll find a solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simplesteph picture simplesteph  ยท  5Comments

miketheman picture miketheman  ยท  3Comments

tmclaugh picture tmclaugh  ยท  4Comments

xedef picture xedef  ยท  3Comments

ceefour picture ceefour  ยท  3Comments