Lambda function python package import problem

0
import json
import langchain
from langchain import LLMChain
def lambda_handler(event, context):
    # res = test_endpoint()
    # res = "lambda is running"
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

When I import langchain only it is not throwing any error but when I import from langchain import LLMChain gives error { "errorMessage": "Unable to import module 'lambda_function': No module named 'pydantic_core._pydantic_core'", "errorType": "Runtime.ImportModuleError", "requestId": "c29d10cc-d012-4eb8-acb1-468537d4d708", "stackTrace": [] } I have added in layer langchain package zip.

Dipika
posta 4 mesi fa519 visualizzazioni
2 Risposte
0

Hi,

Some other folks are having similar problem when running Lambdas on ARM: https://github.com/pydantic/pydantic/issues/6557

It seems that the solution is to use Lambda runtime 3.10 or above.

Can you try that?

Best,

Didier

profile pictureAWS
ESPERTO
con risposta 4 mesi fa
profile picture
ESPERTO
verificato 2 mesi fa
0

Hi,

In lambda, it's not possible to import modules from https://pypi.org. It supports only boto3 and all default modules under python package, none other. To sort this out, I would suggest to install modules in present non-default directory in your local system by using below command, so that you will see the modules are installed in your present directory. Post that you can zip module files with your code together, then upload it to lambda.

Command: pip install <module-name> -t . --no-user

iamAni
con risposta 4 mesi 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