AWS Lambda (python, zip file): Phase: invoke Status: timeout, source error comes from importing a sub-module

0

Hello,

I’m having problems with my 1st AWS lambda function in python (zip file) that give me the following error: Phase: invoke Status: timeout. Not very informative, but after various tests, the source of the error is the importation of a sub-module.

My function imports:

import json
import phonenumbers as pn           # version 8.13.30
from phonenumbers import geocoder as gc

The timeout error comes from

from phonenumbers import geocoder as gc

, which is for me perfectly correct.

When I comment this line, the function runs correctly, except the command that uses geocoder (obviously) and gives errors catch by “except” statements.

The phonenumbers lib was installed in AWS CloudShell (pip install phonenumbers, namely phonenumbers-8.13.30-py2.py3-none-any.whl), all __pycache__ removed, Lambda has 644 permissions and 755 permissions for directories.

Zip file architecture:

my_function
|- phonenumbers
		|- ...
		|- geocoder.py
		|- ...
|- lambda_function.py
|- data.json

The function works like a charm without error in AWS CloudShell python command line (importing my locally installed phonenumbers). But not in AWS Lambda!

The only line that uses geocoder (gc) is: gc.description_for_number(CallerID_determined_pn, "en")

I tried many things, including not import geocoder and using pn.geocoder.description_for_number but it gives error: AttributeError: module 'phonenumbers' has no attribute 'geocoder'.

I’m running out of ideas and any advice or solution would be more than welcome.

Best, Lionel

Lionel
已提問 3 個月前檢視次數 149 次
2 個答案
0

Hi Lamderson,

Thanks for the idea, but unfortunately it doesn't fix the problem :-(

Hoping new answer...

Lionel
已回答 3 個月前
-1

Since that is a lib you need, why don't you try adding it to the Lambda layer and just import the layer instead of adding it to the zip?

Like this:

import json
import phonenumbers as pn           # version 8.13.30
import geocoder as gc

In the Zip you would only have

my_function
|- lambda_function.py
|- data.json

Try using this and see if you get a timeout error...

已回答 3 個月前
profile picture
專家
已審閱 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南