简体   繁体   中英

AWS Lambda Python error - Runtime.ImportModuleError

I am running the AWS Step by step guide for following link .

I am currently on Step 4. - Create the Lambda function that splits input data

I am running on a Windows 10 machines with Python installed:

pip 20.2.3 -  (python 3.9)

The Lambda function on AWS is failing with following:

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'fsspec'",
  "errorType": "Runtime.ImportModuleError"
}

Function Logs

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'fsspec'

Please recommend any solution.

My solution was to add the fsspec library at a custom layer. First of all you need to create a Custom Layer. Open your terminal:

mkdir python
cd python
pip3 install fsspec -t .

Install inside this folder any other file you may need.

cd ..
zip -r fsspec_layer.zip python

This is the zip file you are going to use to create your custom layer. Do the following:

  1. Go to AWS LAMBDA -> Layers
  2. Create the Layer

拉姆达层

  1. At your Lambda Functions Panel Select Layer

拉姆达函数

  1. Select the layer you created

在此处输入图像描述

Then try to execute it again.

The issue was with the file permissions. I was zipping the files on Windows 10 machine and due to some reason the files are not having execute permission. The function is able to run once the permissions are set correctly using a Mac:

Commands used - 

 1. chmod -R +x *.py
 2. zip xyz.zip *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM