serverless-localstack icon indicating copy to clipboard operation
serverless-localstack copied to clipboard

Getting TypeError while trying to deploy a Serverless framework Python lambda with mountCode: true

Open srinivaskalyani opened this issue 3 years ago • 2 comments
trafficstars

I followed the instructions provided in the official documentation to execute a custom Python lambda using the Serverless framework. I am using the following command to deploy the lambda from the my_serverless_root directory:

LAMBDA_MOUNT_CWD=$(pwd)/build/hot serverless deploy --stage local

Following is my serverless.yml :

service: thetenant-service
plugins:
  - serverless-python-requirements
  - serverless-pseudo-parameters
  - serverless-localstack

custom:
  pythonRequirements:
    dockerizePip: false
  localstack:
    stages:
      - local
    debug: true
    host: http://localhost
    edgePort: 4566
    region: us-east-1
    lambda:
      mountCode: true

package:
  exclude:
    - ./**
  include:
    - my_serverless_root/**

provider:  
  name: aws
  runstime: python3.7
  stage: ${opt:stage, 'default_stage'}
  tenant: thetenant
  region: us-east-1
  deploymentBucket: my-deployment-bucket
  role: arn:aws:iam::#{AWS::AccountId}:role/MyLambdaExecutionRole
  environment:
    STAGE: ${self:provider.stage}
    TENANT: ${self:provider.tenant}

functions:
  my_function:
    name: ${self:provider.tenant}-my-function
    handler: my_handler_dir.aws.my_handler_file.handler
    events:
      - http: POST /my_api/endpoint

I am getting the following error while trying to deploy:

  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
      at readFile (node:fs:393:10)
      at go$readFile (/home/srinivas/.nvm/versions/node/v16.13.0/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:118:14)
      at readFile (/home/srinivas/.nvm/versions/node/v16.13.0/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:115:12)
      at go$readFile (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/graceful-fs/graceful-fs.js:118:14)
      at Object.readFile (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/graceful-fs/graceful-fs.js:115:12)
      at Object.readFile (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/serverless-python-requirements/node_modules/universalify/index.js:5:57)
      at Object.tryCatcher (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/util.js:16:23)
      at Object.ret [as readFileAsync] (eval at makeNodePromisifiedEval (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:14:23)
      at injectRequirements (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/serverless-python-requirements/lib/inject.js:27:6)
      at ServerlessPythonRequirements.injectAllRequirements (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/serverless-python-requirements/lib/inject.js:149:13)
      at ServerlessPythonRequirements.<anonymous> (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/serverless-python-requirements/index.js:218:43)
      at ServerlessPythonRequirements.tryCatcher (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/home/srinivas/work/my_root_dir/integrations/my_serverless_root/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (node:internal/timers:464:21)

The same error occurs with both localstack cli as well as the standard non-customized docker-compose.yml file provided here.

srinivaskalyani avatar Dec 30 '21 07:12 srinivaskalyani

Hi @whummer, did you get a chance to look into this?

srinivaskalyani avatar Jan 06 '22 14:01 srinivaskalyani

I think I got this same error when I was deploying a Serverless service that had the serverless-python-requirements plugin but no requirements file. I had just made a service with some cloudformation scripts without any actual functions so the plugin was redundant. I guess that the plugin might be looking for the requirements file and fails if not found. I got rid of the error by removing the plugin that I didn't need in the service. Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined at readFile (node:fs:393:10)...

Seeing the same error on my Linux build. Windows builds and deploys perfectly. Not sure why serverless won't build the .zip in .serverless on Linux? My setup on both builds is identical. Other than build env linux Environment: win32, node 16.18.0, framework 3.25.1 (local) 3.24.1v (global), plugin 6.2.2, SDK 4.3.2 Credentials: Local, "default" profile Docs: docs.serverless.com Support: forum.serverless.com Bugs: github.com/serverless/serverless/issues

HatmanStack avatar Dec 22 '22 02:12 HatmanStack

Hi @srinivaskalyani, @andreas-rydefalk-diversey, @HatmanStack,

apologizes for the late reply. Do you still experience this issue with the latest serverless-plugin and the latest localstack version?

steffyP avatar Oct 13 '23 09:10 steffyP

Hi @steffyP ,

Actually my error was just a similar looking error that was related to the serverless-python-requirements plugin, not to this serverless-localstack plugin. I found this when googling with the error message.

Hi @steffyP,

Thank you for getting back to me. After encountering the original issue, we never really moved ahead with using the serverless-localstack plugin. Please allow me to try this again, also accounting for @andreas-rydefalk-diversey's suggestions and get back to you sometime this week.

srinivaskalyani avatar Oct 16 '23 07:10 srinivaskalyani

Hi @srinivaskalyani, do you have any updates in the meantime?

steffyP avatar Dec 15 '23 10:12 steffyP

Hi @steffyP, apologies for the delay here. I created a fresh project and no longer face this issue.

srinivaskalyani avatar Mar 14 '24 06:03 srinivaskalyani

Some errors takes you on the edge and this was the error for me, it took me 2 days googling and doing RND and found this:

https://stackoverflow.com/questions/77354288/no-module-named-pydantic-core-pydantic-core-server-for-python-serverless-on-a

This worked for me.

Hope this help.

jagdish1o1 avatar May 10 '24 07:05 jagdish1o1