I imported boto3
for my lambda function in python. When i test lambda it gives this error : No module named boto3
which is rather expected.
Then i referred to the docs,to this link to be exact https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html and realized i need to create a deployment package the issue is i didn't understand the docs well enough to keep up and would like them to be explained again in a simpler way by someone that has already done the required steps.

- 6,622
- 6
- 38
- 64

- 71
- 1
- 7
-
you don't need to install boto3 library separately, copy and paste your function to Lambda it will work fine. – sid8491 Jan 11 '18 at 12:32
-
correct i adjusted that part but i need to import `api.ai` so the problem stays. – user9127040 Jan 11 '18 at 12:34
-
ok i will write the steps. – sid8491 Jan 11 '18 at 12:36
-
@sid8491 you should check https://stackoverflow.com/questions/48210904/python-adjustment-for-user-input-in-lambda if possible – user9127040 Jan 11 '18 at 15:46
1 Answers
You need to make a folder in your local system, install the required libraries into that folder, zip the contents of the folder and upload the zipped file to the AWS Lambda.
- Make a folder in local system
I don't think you need help in this. Lets suppose you made a folder in D drive named yellow-bot
- Install the required libraries into the folder
You can install the required packages in the folder using below command
pip install {package-name} -t "{path-to-project-dir}"
In your case it would be:
pip install apiai -t "D:\yellow-bot"
- Zip the contents of the folder
Now after installing the required libraries there will be multiple files and folders in your yellow-bot folder. You need to select all and zip the content. Please note that do not zip the folder, instead you go inside the folder and zip the contents.
It would be something like below screenshot.
- Create lambda function and upload zip
Now go to AWS Lambda, create a lambda function, give correct run-time and all that. Then select upload zip
file in code entry type
. Select your zip and click on upload.
Make sure to give correct Handler
.
It follows naming convention as:
The filename.handler-method value in your function. For example, "main.handler" would call the handler method defined in main.py.
Since in this case I have uploaded
connector.py
file and entry function was called lambda_handler()
so correct Handler
would be connector.lambda_handler
Click on Save
and you are done.
Hope it helps.

- 6,622
- 6
- 38
- 64
-
Took the same route but couldn't save because it says fix the errors before u can save – user9127040 Jan 11 '18 at 13:48
-
-
Fixed it but another issue appeared, went to the logs and it still doesn't recognize api.ai, the exact error message is `Unable to import module 'lambda_function': No module named apiai` . – user9127040 Jan 11 '18 at 14:21
-
Oh i work on linux so the compression wasn't zip by default, i noticed and fixed that. – user9127040 Jan 11 '18 at 14:24
-
So, what to do when we modify the python code, do we have to zip and upload all the time or can we just modify the code. – arqam Oct 25 '18 at 10:31
-
@arqam once you upload the zip file, all files can be opened in it's online editor (assuming its not too big). you can edit their, or can uplaod the zip file again. – sid8491 Oct 25 '18 at 11:18
-
@sid8491 Thanks for the reply. So only when we need to add a new library then only we have to add the new .zip file right? – arqam Oct 26 '18 at 08:12
-
@arqam yes. but i like to do development on local system so i upload zip file everytime. one more thing, if your zip file is very large (i think more than 200mb) then you need to upload it on s3 and give link here. – sid8491 Oct 26 '18 at 08:29