How can I use pymongo in a lambda function?
After following the instructions from AWS - https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html#python-package-dependencies, I've found that the pymongo library is not recognized by my lambda handler function, but other local packages are.
The python-dateutil is a local package that works as expected , however the pymongo package is not recognized as an import and fails when run.
My file name is correctly listed in the lambda handler function as well (hotel-car-rental.lambda_handler) and other local package imports work fine. So I believe it is something to do with pymongo? How can I get pymongo to work with aws lambda?
Here is the lambda file structure:
- BookTrip
- dateutil
- pymongo
- hotel-car-rental.py
Here is the code:
import json
import datetime
import dateutil.parser # <--- Works with local package
import logging
from pymongo import MongoClient # <--- Does NOT work with local package
# --- Main handler ---
def lambda_handler(event, context):
"""
Route the incoming request based on intent.
The JSON body of the request is provided in the event slot.
"""
logger.debug('event.bot.name={}'.format(event['bot']['name']))
return dispatch(event)