Skip to content

Fix corrupted zip archive in case of same module #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

st4lk
Copy link

@st4lk st4lk commented Apr 25, 2018

Problem

We have different functions with different runtime (not only python) defined in serverless.yml.
For python runtime, there are several functions defined in one file with same dependencies.
To be able to build a package, I have to specify the module param, since requirements for our python functions are not placed in a root folder of the project.

Project structure (simplified):

my-serverless-project
├── api
│   ├── users
│   │   ├── handlers.py
│   │   └── requirements.txt
│   └── generator
│       └── some-non-python-functions-here
└── serverless.yml

In api/users/handlers.py we have several functions:

def func1(event, context):
    # ...


def func2(event, context):
    # ...

serverless.yaml (some directives are omitted for simplicity):

package:
  individually: true


  functions:
    generator:
      runtime: non-python
      # ...
    func1:
      handler: handlers.func1
      module: api/users
      runtime: python3.6
      events:
        - http:
            path: one
            method: get
    func2:
      handler: handlers.func2
      module: api/users
      runtime: python3.6
      events:
        - http:
            path: two
            method: get

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true
    dockerImage: lambci/lambda:build-python3.6

As you can see, both func1 and func2 are declared in same python file, but these are different lambda functions. And they have same dependencies, i.e. same requirmemnts.txt file. We found such code structure useful.

When I try to create a package:

sls package

The resulting archive in .serverless/api/users.zip is corrupted. I suppose the reason is that serverless-python-requirements creates zip archives for different functions asynchronously. Since both functions have same module path - they have same artifact archive.
I can't unzip it and deploy is not working as well.

The archive is fine when I delete func2 from serverless.yml.

Solution

The easiest solution that comes to my mind is to include func name to the artifact zip archive. In that way it works well.

@st4lk st4lk force-pushed the fix-corrupted-zip-archive branch from ae98476 to a902f17 Compare April 25, 2018 08:29
@st4lk
Copy link
Author

st4lk commented Apr 25, 2018

  • One more update (2nd commit): do not try to install requirements for non-python runtime.
    Otherwise, sls shows this error:
  ENOENT: no such file or directory, open 'requirements.txt'

@dschep
Copy link
Contributor

dschep commented Apr 25, 2018

Merged & linted into pr #180 since i think this ifxes some issues i was having in that pr.

dschep added a commit that referenced this pull request Apr 25, 2018
dschep added a commit that referenced this pull request Apr 26, 2018
* Better mixed runtime & function deploy handling

fixes #161 and fixes #179

* another tweak

* fix again?

* Fix corrupted zip archive in case of same module

* Do not try to install requirements for non-python runtime

* Fix lint

* format

* update test for merging #181

*  @AndrewFarley's fix

* huh. depcheck sucks.

* fixix syntax error
@dschep
Copy link
Contributor

dschep commented Apr 26, 2018

Merged #180 which contained the changes from this PR too. I'd love it if you could test this change before I push to npm. Install with npm i UnitedIncome/serverless-python-requirements

@dschep dschep closed this Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants