How to import a python module in multiple lambda function?

+1 vote
I have a couple of AWS Lambda functions. I have my  functions in a separate file called functions.py. I want to import this module in all of my AWS Lambda functions. I am unable to find a place to store this module (functions.py), so that when I make a change in this module I don't have to change anything in my Lambda functions.
Mar 26 in AWS by ravi
24 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

setup your helper function in your file system like this:

pathToSomewhere/my/functions.py
pathToSomewhere/my/__init__.py
pathToSomewhere/setup.py

Where __init__.py is:

from .helper_functions import *

and setup.py is

from setuptools import setup

setup(name='my',
      version='0.10000',
      description='My functions',
      url='http://github.com/user/example',
      license='Proprietary',
      author='Null',
      author_email='null@example.com',
      packages=['my'],
      install_requires=['boto3'],
      zip_safe=False)

Now let's package up my_helper. From pathToSomewhere/ run:

python setup.py sdist

I'm assuming you already know how to create and upload a virtual environment for running your lambda function. If not, let me know.

Now let's install my_helper into the virtual env of your lambda function. Let's assume your virtual environment is called worker_env

./worker-env/bin/pip install file://pathToSomewhere/my

Now zip up worker-env and your actual lambda script and upload that.

This will work fine.

answered Mar 26 by Esha

Related Questions In AWS

0 votes
1 answer

how to import numpy and pandas inside aws lambda function?

The problem is that your local numpy ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 56,120 points
1,242 views
0 votes
1 answer

How do I add python libraries to an AWS lambda function for Alexa?

As it is described in the Amazon ...READ MORE

answered Oct 23, 2018 in AWS by Archana
• 3,770 points
86 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

How to kill a lambda function in AWS?

$ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions ...READ MORE

answered Mar 28 in AWS by Shashank
• 1,350 points
92 views
+1 vote
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.