0

I have followed this guide last year to build my AWS python archive and it was working.

Today i have automated my code deployment and it was not working (i am using shutil.make_archive("package", 'zip', root_dir=path, base_dir="package/", verbose=True) instead of the zip -r package.zip package/ command now.

But when i start doing all these steps manually again and deploy (without the automated code) it's not working anymore.

Here is what my folders look like :

enter image description here

enter image description here

The only thing that has changed since the last time it was working is the pymongo version which was 3.12 instead of 4.3.3.

My handler is :

def lambda_handler(event, context):
    print(event)

The error i am getting from CloudWatch :

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'pymongo'
Traceback (most recent call last):

What am i doing wrong ?

EDIT :

I have found an old dependency package that is working, but that is using more than just pymongo[srv] so i will check what may be different but the error comes from the dependencies.

0

2 Answers 2

2

For lambda to find your external dependency, all your dependency must be inside audio-handler folder and not package. By default, lambda looks for dependency in the root directory.

audio-handler
 |-bson
 |-pymongo
 .
 .
 .
 |-lambda_function.py

Here is the video on how to create your deployment package and deploy it on aws lambda https://www.youtube.com/watch?v=Jtlxf_kn5zY

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks indeed i was zipping the package folder instead of its content recursively.
0

I would strongly advise that you use a Lambda Layer to import external modules, ensuring your packaged components are at the root of the project and not within a directory named package.

Add External Python Libraries to AWS Lambda using Lambda Layers https://www.linkedin.com/pulse/add-external-python-libraries-aws-lambda-using-layers-gabe-olokun

2 Comments

Thanks for your answer and the link you provided, but adding the layer didn't change anything i am stil lgetting the error. This is so weird as it was working fine last week.. could this come from the dependencies themselves ? I am installing pymongo[srv] as a dependency
Expose the dependencies under Audio-Handler directory and remove the packages directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.