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
posta 3 mesi fa149 visualizzazioni
2 Risposte
0

Hi Lamderson,

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

Hoping new answer...

Lionel
con risposta 3 mesi fa
-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...

con risposta 3 mesi fa
profile picture
ESPERTO
verificato un mese fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande