serverless-package-python-functions icon indicating copy to clipboard operation
serverless-package-python-functions copied to clipboard

Include option to maintain the file include paths when copying to build package

Open ubaniabalogun opened this issue 8 years ago • 8 comments

ubaniabalogun avatar Sep 05 '17 13:09 ubaniabalogun

see #8 first comment

ubaniabalogun avatar Sep 05 '17 13:09 ubaniabalogun

I think I've solved this issue in my fork at onlicar/serverless-package-python-functions - I've added a new resources option alongside includes and a globalResources option to custom. We have resources on our serverless API like html email templates so we need to copy files in place.

I don't really see a use case for includes as it currently stands - why would you need to copy files to the top level of the lambda zip? I think all users of this plugin will need to copy files in place so that the code structure is the same whether we are online or offline. e.g. when I import a file likerepositories/vehicle.py I do this:

from repositories.vehicles import get_vehicle

Whereas, with includes the way it stands, it would have to be changed to this, (somehow) just for deployment:

from vehicles import get_vehicle

Let me know if I should open a pull request with the current changes (adding resources alongside includes so not a breaking change) or open one that overwrites the includes implementation (breaking change).

danbovey avatar Oct 17 '17 16:10 danbovey

+1

JFox avatar Oct 24 '17 14:10 JFox

@danbovey Thanks for the feedback! Please make a PR request and I'll take a look.

ubaniabalogun avatar Oct 25 '17 04:10 ubaniabalogun

I think I've solved this issue in my fork at onlicar/serverless-package-python-functions - I've added a new resources option alongside includes and a globalResources option to custom. We have resources on our serverless API like html email templates so we need to copy files in place.

I don't really see a use case for includes as it currently stands - why would you need to copy files to the top level of the lambda zip? I think all users of this plugin will need to copy files in place so that the code structure is the same whether we are online or offline. e.g. when I import a file likerepositories/vehicle.py I do this:

from repositories.vehicles import get_vehicle

Whereas, with includes the way it stands, it would have to be changed to this, (somehow) just for deployment:

from vehicles import get_vehicle

Let me know if I should open a pull request with the current changes (adding resources alongside includes so not a breaking change) or open one that overwrites the includes implementation (breaking change).

Hi,

How did you solve this issue? I am having very similar issue. Whenever I have to run my unit tests, my import doesn't work. If I change my imports to suit unit tests then aws lambda doesn't like it.

Is there any workaround for this?

Regards, Ashish

ashishgajabi avatar Mar 11 '19 13:03 ashishgajabi

As of now, for my unit test cases, I have solved the problem with setting PYTHONPATH. But is there cleaner way of handling this scenario?

Regards,

ashishgajabi avatar Mar 11 '19 22:03 ashishgajabi

Is this feature being worked upon? We are facing a similar condition where we need to copy files in place to a lambda package.

rishabhdas avatar Mar 05 '20 05:03 rishabhdas

Hi @danbovey. Did you happen to end up with a solution for this?

As already mentioned here, not having each lambda as an individual package introduces all kinds of issues when you start add unit tests, linting with mypy, etc. to the project.

ericbn avatar May 14 '22 22:05 ericbn