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 ?
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.
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")
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
Most helpful comment
Ok i've figured out, bin files needs to be in /tmp in order to be excuted !