Lambda Import Module Error Python

0

I am experiencing an issue with my AWS Lambda function where I'm unable to import the firebase_admin module from a Lambda layer, despite the layer being correctly attached and the module being visibly present in the /opt directory.

  • I have created a Lambda layer that includes the firebase_admin module among others.
  • The layer is attached to my Lambda function.
  • I verified the contents of /opt directory using os.listdir('/opt') in the Lambda function, and it lists firebase_admin and its associated files.
  • Despite this, the Lambda function fails to import the firebase_admin module with an ImportModuleError.

Steps Taken:

  1. Created a Lambda layer with the necessary Python packages, including firebase_admin.
  2. Set correct file permissions (644 for files, 755 for directories) before zipping the layer.
  3. Uploaded the layer to AWS Lambda and attached it to the function.
  4. Verified the presence of the firebase_admin package in the /opt directory through Lambda function logs.
  5. Tried explicitly adding /opt/python to sys.path at the beginning of the Lambda function.

Error Encountered: [ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'firebase_admin'

Are there any additional steps or configurations I might be missing? I also tried resolution mentioned in https://repost.aws/knowledge-center/lambda-import-module-error-python. But I still get the same error.

Enter image description here

MS
gefragt vor 5 Monaten361 Aufrufe
1 Antwort
1

As can be seen in the documentation here, the content in the layer should not be in the root, but rather, in a subfolder, based on the runtime. In the case of Python, the libraries should be either under python, or python/lib/python3.x/site-packages.

profile pictureAWS
EXPERTE
Uri
beantwortet vor 5 Monaten
profile picture
EXPERTE
überprüft vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen