Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

341
Views
Unable to import modules from aws lambda layer

I have a requirements file for my pip packages. I installed it in a target folder and zipped the contents and uploaded it on AWS lambda layer.

Requirements.txt

asgiref==3.2.3
certifi==2019.11.28
chardet==3.0.4
cloudevents==0.2.4
decorator==4.4.1
Django==3.0
idna==2.8
jaeger-client==4.2.0
jsonpath-ng==1.4.3
pbr==5.4.4
ply==3.11
pytz==2019.3
requests==2.22.0
six==1.13.0
sqlparse==0.3.0
urllib3==1.25.7
aws-xray-sdk
mysql-connector-python
gunicorn

I used the command pip3 install -r requirements.txt -t python/ where python is the target directory. This image shows the content of python directory. enter image description here

After this I zipped the content of this directory and published it as a layer on aws lambda. I made a dummy lambda function to check if the layer is working or not.

import json
import django

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

The log file error :

Response:
{
  "errorMessage": "Unable to import module 'lambda_function'"
}

Request ID:
"66ce85e0-59f0-4e5c-98f9-6fa3e3eb17d0"

Function Logs:
START RequestId: 66ce85e0-59f0-4e5c-98f9-6fa3e3eb17d0 Version: $LATEST
Unable to import module 'lambda_function': No module named 'django'

END RequestId: 66ce85e0-59f0-4e5c-98f9-6fa3e3eb17d0
REPORT RequestId: 66ce85e0-59f0-4e5c-98f9-6fa3e3eb17d0  Duration: 0.64 ms   Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 42 MB  Init Duration: 1.81 ms  
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If layer would suite you, I can let you know that I just successful constructed a django layer based on your requirements.txt file which could be imported in lambda.

To build the layer I used lambci/lambda tool. To ease the process, I used the following snippet from here.

The layer had 42 MB which is close to the 50 MB limit of lambda.

If you don't want to use layer, you can also use the same docker tool to build regular deployment package as explained in the recent AWS blog:

  • How do I create a Lambda layer using a simulated Lambda environment with Docker?

Since layer works, including django in a regular package should also work.

over 4 years ago · Santiago Trujillo Report

0

You mention that you 'zipped the content of this directory' referring to the python folder. When you create a layer via a .zip package, python packages need to be in a 'python' folder subdirectory. They can not be all at the root of the zipped folder.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!