Search code examples
pythonpython-3.xaws-lambdaelasticsearch-curator

Unable to import module 'lambda_function': No module named 'error'


I have a simple Python Code that uses Elasticsearch module "curator" to make snapshots. I've tested my code locally and it works.

Now I want to run it in an AWS Lambda but I have this error :

Unable to import module 'lambda_function': No module named 'error'

Here is how I proceeded :

I created manually a Lambda and gave it a "AISA-BasicLambdaExecutionRole" role. Then I created my package with my function and the dependencies that I installed with the command :

pip install elasticsearch-curator -t /<path>/myRepository 

I zipped the content (not the folder) and uploaded it in my Lambda. I changed the Handler name to "lambda_function.lambda_handler" (my function's name is "lambda_function.py").

Did I miss something ? This is my first time working with Lambda and Python

I've seen the other questions about this error :

"errorMessage": "Unable to import module 'lambda_function'"

But nothing works for me.

EDIT :

Here is my lambda_function :

from __future__ import print_function
import curator
import time
from curator.exceptions import NoIndices
from elasticsearch import Elasticsearch

def lambda_handler(event, context):



  es = Elasticsearch()

  index_list = curator.IndexList(es)

  index_list.filter_by_regex(kind='prefix', value="logstash-")

  Number = 1

  try:
    while Number <= 3:

        Name="snapshotLmbd_n_"+ str(Number) +""

        curator.Snapshot(index_list, repository="s3-backup", name= Name , wait_for_completion=True).do_action()     
        Number += 1

        print('Just taking a nap ! will be back soon')
        time.sleep(30)

  except KeyboardInterrupt:
        print('My bad ! I interrupted this')
        return

Thank you for your time.


Solution

  • Ok, since you have everything else correct, check for the permissions of the python script.

    It must have executable permissions (755)