Skip to content

Executable may have wrong permissions #293

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
JulienMarliac opened this issue Nov 29, 2018 · 3 comments
Closed

Executable may have wrong permissions #293

JulienMarliac opened this issue Nov 29, 2018 · 3 comments

Comments

@JulienMarliac
Copy link

Hi all,

I'm trying to run a chromium scrapper (with selenium) on python lambda using :

OS:                    win32
Node Version:          8.9.4
Serverless Version:    1.33.2
Python:                3.6
Selenium:              3.141.0

When I check the package with WSL (Windows Subsystem for Linux) the rights seems good :

-rwxrwxrwx 1 user user 7874704 janv.  1  1980 chromedriver
-rwxrwxrwx 1 user user 109319976 janv.  1  1980 headless-chromium

But when I try to call the lambda I get

Message: 'chromedriver' executable may have wrong permissions.

Any ideas ?

@bsamuel-ui
Copy link
Contributor

You should have your script log the output of ls -al to see what permissions are actually set in lambda. Builds should break if the permissions aren't preserved. (See #233 and #166.)

You can also check the attributes directly using python -c 'import zipfile; print("\n".join(map(repr, zipfile.ZipFile(".serverless/your-project.zip").infolist()))'

Looking at this thread it looks like it's sensitive to where it's located and a bunch of other things, so the error message may be misleading. If it needs to be at /usr/local/bin, you're SOL as that's not writeable in lambda.

@JulienMarliac
Copy link
Author

Ok i've figured out, bin files needs to be in /tmp in order to be excuted !

import os
import subprocess
import shutil
import time

BIN_DIR = "/tmp/bin"
CURR_BIN_DIR = os.getcwd() + "/bin"


def _init_bin(executable_name):
    start = time.clock()
    if not os.path.exists(BIN_DIR):
        print("Creating bin folder")
        os.makedirs(BIN_DIR)
    print("Copying binaries for " + executable_name + " in /tmp/bin")
    currfile = os.path.join(CURR_BIN_DIR, executable_name)
    newfile = os.path.join(BIN_DIR, executable_name)
    shutil.copy2(currfile, newfile)
    print("Giving new binaries permissions for lambda")
    os.chmod(newfile, 0o775)
    elapsed = time.clock() - start
    print(executable_name + " ready in " + str(elapsed) + "s.")


def handler(event, context):

    _init_bin("headless-chromium")
    _init_bin("chromedriver")

@CaseGuide
Copy link

CaseGuide commented Jul 27, 2020

Note to people who land here googling this error. @JulienMarliac's solution works so long as you then also load it from that location (duh). I posted full example code here: https://stackoverflow.com/questions/56082021/issue-running-selenium-on-aws-lambda/63122479#63122479

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

No branches or pull requests

3 participants