Unable to run binary from python aws lambda function

I am trying to run this tool in a lambda function: https://github.com/nicolas-f/7DTD-leaflet

The tool depends on the cushion, which depends on image libraries that are not available in the AWS lambda container. To try to get around this, I ran pyinstaller to create a binary that I hope will execute. This file is called map_readerand is at the top level of the zambda zip package.

Below is the code that I use to try to run this tool:

command = 'chmod 755 map_reader'
args = shlex.split(command)
print subprocess.Popen(args)

command = './map_reader -g "{}" -t "{}"'.format('/tmp/mapFiles', '/tmp/tiles')
args = shlex.split(command)
print subprocess.Popen(args)

And here is the error that occurs during the second call subprocess.Popen:

<subprocess.Popen object at 0x7f08fa100d10>
[Errno 13] Permission denied: OSError

How can I run this correctly?

+9
5

, , .

, . , , . , , ,

chmod: map_reader: No such file or directory

2:

  1. map_reader /tmp. /tmp/map_reader.
  2. , AWS Lambda, AWS Lambda:

; ZIP , ( ZIP ), Node.js , . , :

process.env[‘PATH] = process.env[‘PATH] + ‘: + process.env[‘LAMBDA_TASK_ROOT]

Node JS, Python, ,

import os os.environ['PATH']

command = './map_reader <arguments> .

- , chmod 755 map_reader ( ).

+6

, , (, ), , bin py lib:

import shutil
import time
import os
import subprocess

LAMBDA_TASK_ROOT = os.environ.get('LAMBDA_TASK_ROOT', os.path.dirname(os.path.abspath(__file__)))
CURR_BIN_DIR = os.path.join(LAMBDA_TASK_ROOT, 'bin')
LIB_DIR = os.path.join(LAMBDA_TASK_ROOT, 'lib')
### In order to get permissions right, we have to copy them to /tmp
BIN_DIR = '/tmp/bin'

# This is necessary as we don't have permissions in /var/tasks/bin where the lambda function is running
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, 0775)
    elapsed = (time.clock() - start)
    print(executable_name+" ready in "+str(elapsed)+'s.')

# then if you're going to call a binary in a cmd, for instance pdftotext :

_init_bin('pdftotext')
cmdline = [os.path.join(BIN_DIR, 'pdftotext'), '-nopgbrk', '/tmp/test.pdf']
subprocess.check_call(cmdline, shell=False, stderr=subprocess.STDOUT)
+5

. -, , /tmp, .

, pyinstaller ubuntu, . , , . pyinstaller ec2 AMI Amazon Linux. .os, tmp , .

+2
copyfile('/var/task/yourbinary', '/tmp/yourbinary')
os.chmod('/tmp/yourbinary', 0555)

/tmp

+1

/tmp. ld-linux , , .

, AWS Lambda :

/lib64/ld-linux-x86-64.so.2 /opt/map_reader

P.S. map_reader -, /opt.

0

Source: https://habr.com/ru/post/1014082/


All Articles