1

I have added a zip file as an deployment package which includes an xxx.py script.

My lambda function should invoke xxx.py script from the package.

My lambda function as below:

libdir = os.path.join(os.getcwd(), 'local', 'lib')
download_path = '/tmp/{}{}'.format(uuid.uuid4(), key)
command = 'LD_LIBRARY_PATH={} python xxx.py "{}"'.format(libdir, download_path)
output_path = subprocess.check_output(command, shell=True)

I get this error:

Command 'LD_LIBRARY_PATH=/var/task/local/lib python xxx.py "/tmp/52513240-a9 returned non-zero exit status 2.: CalledProcessError

My deployment package has xxx.py file within few subfolders in the zip file.

Do I need to set environment variable in my lambda function? If yes, what could be the key and value in my case.

Is there any other way than this to call an python script from deployment package in lambda?

Please help. Thanks in advance!

Adi Dembak
  • 2,433
  • 2
  • 18
  • 26
R S
  • 21
  • 2
  • If you have put your package in `AWS Layer`, then you can directly invoke it in Lambda by using `import` like `import package_name`. – Mayank Porwal May 06 '20 at 19:21

2 Answers2

0

Thanks Mayank, but still - how do I call the main function of .py file from my lambda function after import.

My lambda function will actually be triggered based on an s3 event which in turn should call the main function from .py script within package and output should be returned into another bucket. This is my overall intend.

R S
  • 21
  • 2
0

rewrite your main in the .py as a function that takes a parameter and in the main of the lamba pass the s3 trigger to the class in your second layer.

pseudocode

inside your second layer

___main(s3_event)___ # or rename from main to some_function
# some code

in your main lambda

import xxx.py as xxx
xxx.___main(s3_event)___
Grom
  • 50
  • 4