0

I wrote a AWS lambda function and got this error:

"errorMessage": "Unable to import module 'lambda_function': No module named 'joblib'",

I imported joblib in the header of my lambda_function.py file:

import boto3
import joblib
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
import io
from io import BytesIO
import pandas as pd
import awswrangler as wr

Anyway around this error?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
justanewb
  • 133
  • 4
  • 15
  • Can similar question & answer help you: [AWS Lambda - unable to import module 'lambda_function'](https://stackoverflow.com/questions/49734744/aws-lambda-unable-to-import-module-lambda-function#49841953) ? – hc_dev Jul 08 '21 at 20:14

1 Answers1

2

Lambda Layer

AWS lambda wraps dependencies in what they call "layers". An AWS lambda layer is essentially a .zip file containing all the packages your lambda function will need (required imports).

See the AWS documentation, section Creating and sharing Lambda layers, for how to create and deploy a layer.

Adding a module to an existing layer

If you are using an existing layer, then you need to add joblib to it, otherwise, you will probably encounter errors when trying to import all those other libraries too.


Absent any other code, there's not much more I can offer.

hc_dev
  • 8,389
  • 1
  • 26
  • 38
myz540
  • 537
  • 4
  • 7
  • 1
    Brief pin-pointing answer! I improved the formatting slightly to make it shine. Hope you don't mind ️ – hc_dev Jul 08 '21 at 20:28