Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14301

Serverless framework with serverless-python-requirements does not work

$
0
0

I opened this thread on github

I'm trying to use libraries in my python backend.I have it deployed with serverless framework. This is my configuration:

serverless.yml:

    plugins:       - serverless-offline       - serverless-python-requirements    custom:       pythonRequirements:         dockerizePip: non-linux         zip: true    functions:       function1:         handler: handlerPV.function1         events:          - httpApi:              path: /function1              method: post       function2:        handler: handlerPV.function2        events:         - httpApi:             path: /function2             method: post       function3:        handler: handlerPV.function3        events:          - httpApi:              path: /function3              method: post

(I have changed the names of the functions to show it here)

My .requirements.txt:

cachetools==5.3.2certificate==2023.11.17charset-normalizer==3.3.2dnspython==2.3.0idna==3.6numpy==1.21.6numpy-financial==1.0.0pymongo==4.6.1requests==2.31.0urllib3>=1.26.0,<2.0.0boto3==1.33.13

The problem I'm having is that when I upload it to AWS with the serverless deploy command I get this error in only some lambda functions. It's strange, because some functions use this library and it works, but in others, it doesn't work..

This is the error un cloudWatch:

[ERROR] Runtime.ImportModuleError: Unable to import module 'handlerSimulationDatabase': No module named 'cachetools' Traceback (most recent call last):

EDIT

I'll tell you about the changes I've made that haven't been successful: I've tried to upload the requirements to a lambda layer, but I haven't had any success with my problem either. I've switched to python 3.8, and have been using pipenv instead of python's native venv. This is the new serverless.yml. I have also tried deleting the lambda functions and creating them again. I am still surprised, since in some functions the cachetools library is used and there is no error, and yet in others, the error appears using both the same function that uses cachetools

service: service-nameframeworkVersion: "3"provider:  name: aws  runtime: python3.8  stage: staging  region: us-east-1  timeout: 29  memorySize: 1024  httpApi:    cors: truepackage:  patterns:    # Folder    - "!node_modules/**"    - "!Lib/**"    - "!build/**"    - "!__pycache__/**"    - "!Include/**"    - "!venv/**"    - "!.serverless/**"    - "!.vscode/**"    - "!preproduction/**"    - "!production/**"    # Files    - "!README.md"    - "!cspell.json"    - "!package-lock.json"    - "!package.json"plugins:  - serverless-offline  - serverless-python-requirementscustom:  pythonRequirements:    dockerizePip: non-linux    usePipenv: true    zip: true

Viewing all articles
Browse latest Browse all 14301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>