I am creating a AWS Lambda python deployment package. I am using one external dependency requests . I installed the external dependency using the AWS documentation http://do
If you are uploading a zip file. Make sure that you are zipping the contents of the directory and not the directory itself.
In lambda_handler
the format must be lambda_filename.lambda_functionName
.
Supposing you want to run the lambda_handler
function and it's in lambda_fuction.py
, then your handler format is lambda_function.lambda_handler
.
Another reason for getting this error is module dependencies.
Your lambda_fuction.py
must be in the root directory of the zip file.
My problem was that the .py file and dependencies were not in the zip's "root" directory. e.g the path of libraries and lambda function .py must be:
<lambda_function_name>.py
<name of library>/foo/bar/
not
/foo/bar/<name of library>/foo2/bar2
For example:
drwxr-xr-x 3.0 unx 0 bx stor 20-Apr-17 19:43 boto3/ec2/__pycache__/
-rw-r--r-- 3.0 unx 192 bx defX 20-Apr-17 19:43 boto3/ec2/__pycache__/__init__.cpython-37.pyc
-rw-r--r-- 3.0 unx 758 bx defX 20-Apr-17 19:43 boto3/ec2/__pycache__/deletetags.cpython-37.pyc
-rw-r--r-- 3.0 unx 965 bx defX 20-Apr-17 19:43 boto3/ec2/__pycache__/createtags.cpython-37.pyc
-rw-r--r-- 3.0 unx 7781 tx defN 20-Apr-17 20:33 download-cs-sensors-to-s3.py
No need to do that mess.
use python-lambda
https://github.com/nficano/python-lambda
with single command pylambda deploy
it will automatically deploy your function
Please add below one after Import requests
import boto3
What I can see that is missing in your code.
I found Nithin's answer very helpful. Here is a specific walk-through:
Look-up these values:
With these values, you would need to rename the handler (shown in the screenshot) to "cool.lambda_handler". This is one way to get rid of the "Unable to import module 'lambda_function'" errorMessage. If you were to rename the handler in your python script to "sup" then you'd need to rename the handler in the lambda dashboard to "cool.sup"