Overview:
I have some C++ code (myProgram
) that I want to execute from a Lambda function. I have built the code on an Amazon Linux EC2 instance, and it runs there without problem.
When I try to run it from a Python script in Lambda, I receive the following error message:
Command 'LD_LIBRARY_PATH=/var/task/lib; /var/task/myProgram -d' returned non-zero exit status 126.: CalledProcessError
I see from the Bash Reference Manual that 126 means the command is found but is not executable. It is executable before I upload it to Lambda, so I'm not sure how to resolve this.
Edit: Thanks to the comment below, I double checked the permissions on the Lambda instance. Indeed, the file is not marked as executable after it has been uploaded. When I try changing it with chmod
, I get an error Read-only file system
.
Details:
When I package this and upload it to my lambda function, the directory structure looks like this:
- handler.py
- myProgram
- lib
- (required libraries)
Here is the code for handler.py
import os
import subprocess
exepath = os.path.join(os.getcwd(), 'myProgram')
libdir = os.path.join(os.getcwd(), 'lib')
def handler(event, context):
command = 'LD_LIBRARY_PATH={}; {} -d'.format(libdir, exepath)
return subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
If I change shell=True
to shell=False
then I receive a different error
[Errno 2] No such file or directory: 'LD_LIBRARY_PATH=/var/task/lib; /var/task/myProgram -d': FileNotFoundError
Question:
How can I make myProgram
executable? I don't see any mention of this process in the Lambda blog on executables