Skip to content

serverless deploy python code issue #111

@fshah7

Description

@fshah7

Hi,

I am trying to deploy my python code on aws lambda using serverless and I am following the below tutorial:
https://serverless.com/blog/serverless-python-packaging/

When I am trying to deploy I get the below error:

Error --------------------------------------------------

Exception:
Traceback (most recent call last):
File "/var/lang/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/var/lang/lib/python3.6/site-packages/pip/commands/install.py", line 388, in run
ensure_dir(options.target_dir)
File "/var/lang/lib/python3.6/site-packages/pip/utils/init.py", line 83, in ensure_dir
os.makedirs(path)
File "/var/lang/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/var/task/.serverless/requirements'

Can anyone help me out with that.

Activity

dschep

dschep commented on Dec 15, 2017

@dschep
Contributor

Hmm. interesting. Could you share your serverless.yml and what operating system you're on?

fshah7

fshah7 commented on Dec 15, 2017

@fshah7
Author

Sure. I am on mac os.
Here the serverless.yml file.

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true1321

service: numpy-test

provider:
  name: aws
  runtime: python3.6

functions:
  numpy:
    handler: handler.main

Here is the handler.py

try:
    import unzip_requirements
except ImportError:
    pass

import numpy as np


def main(event, context):
    a = np.arange(15).reshape(3,5)
    print("Array is ",a)

if __name__ == "__main__":
        main('', '')
dschep

dschep commented on Dec 15, 2017

@dschep
Contributor

Hmm. I assume you're using Docker for Mac? Is this project inside your home directory(within /Users)?

fshah7

fshah7 commented on Dec 15, 2017

@fshah7
Author

Yes I am using docker for mac. The project is under my home directory

fshah7

fshah7 commented on Dec 15, 2017

@fshah7
Author

Just FYI,

I am following this blog: https://serverless.com/blog/serverless-python-packaging/

and facing the issue when I try serverless deploy

pr130

pr130 commented on Jan 29, 2018

@pr130

I have the same issue on mac. directory is a subdirectory of my home directory.

This is what our serverless looks like. Weirdly, it works for my colleagues who're on mac os as well, just not for me.

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true
(...)
dschep

dschep commented on Jan 29, 2018

@dschep
Contributor

How do you & your colleagues have docker installed? My mac using colleagues use Docker for Mac and it works for them. Are you maybe using an older docker on mac technique such as docker-machine or boot2docker?

pr130

pr130 commented on Jan 29, 2018

@pr130

Thanks for the fast reply. I have Docker for Mac and I think my colleagues have that as well.
I have had some issues with docker itself (long startup, some hangups (needed to restart)) but it's up and running now.

Some other info: I installed the plugin like it is described on the serverless website, not how you guys wrote in the readme. is that relevant?

I also ran the command with debug on and this is the stack trace just in case there's something totally obvious. Tbh, i think it's something with my setup and permissions to my user, so i'll do some more digging into that tomorrow and post what i've found here as at least someone had the same problem.

Error: Exception:
Traceback (most recent call last):
  File "/var/lang/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/var/lang/lib/python3.6/site-packages/pip/commands/install.py", line 388, in run
    ensure_dir(options.target_dir)
  File "/var/lang/lib/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/var/lang/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/var/task/.serverless/requirements'

    at ServerlessPythonRequirements.installRequirements (/Users/frie/Documents/(root of project path)/node_modules/serverless-python-requirements/lib/pip.js:106:11)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:368:22)
    at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:386:17)
    at Deploy.BbPromise.bind.then.then (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:123:50)
From previous event:
    at Object.before:deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:113:10)
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:368:55)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:368:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:399:17)
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:102:33)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:89:74)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:42:50)
    at <anonymous>
dschep

dschep commented on Jan 29, 2018

@dschep
Contributor

That installation technique is fine, the sls plugin install command is a newer addition to serverless. Alas nothing jumps at at me in that trace back ☹️

memarsh

memarsh commented on Feb 20, 2018

@memarsh

@friep Did you ever find a solution for this problem?

pr130

pr130 commented on Mar 14, 2018

@pr130

@memarsh no unfortunately not.. i was able to use dockerizePip=false for a while but now I'd really need to use =true because we need to compile stuff. So I'm back to this problem.

bsamuel-ui

bsamuel-ui commented on Nov 29, 2018

@bsamuel-ui
Contributor

Can anyone following confirm this is still an issue?

ramisvik

ramisvik commented on Jun 12, 2019

@ramisvik

Do we have a solution for this issue?

wichon

wichon commented on Oct 18, 2019

@wichon

I am having the same issue (Using Fedora 30), the only way that I found to make it work is to extract the generated zip artifact (inside .serverless) change the file permissions, zip it again and manually upload it to the function.

So I guess the file permissions inside the package are somehow inherited by the ones set in the OS. So is there a way to modify this permissions before creating the zip package?

bbock

bbock commented on Jun 24, 2020

@bbock

I have had similar problems. My umask was set to 027, so not world readable, and the Lambda user obviously does not match my UID and GID.

I was able to fix permission problems with setting umask properly (and removing caches to force file creation in proper mode:

umask 027
rm -rf .serverless/*.zip
rm -rf ~/Library/Caches/serverless-python-requirements/*
serverless deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bbock@dschep@memarsh@wichon@pr130

        Issue actions

          serverless deploy python code issue · Issue #111 · serverless/serverless-python-requirements