serverless / compose

Orchestrate Serverless Framework in monorepos
https://serverless.com/framework/docs/guides/compose
MIT License
111 stars 15 forks source link

Command arg parsing choking when using "deploy function" on a service #98

Closed jmoyers closed 2 years ago

jmoyers commented 2 years ago
yarn serverless --service=test-lambda-1 deploy function -f test-lambda-1

Error:
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at resolveArgsSchema (/Users/jmoyers/dev/narnia/node_modules/serverless/lib/cli/resolve-input.js:14:45)
    at /Users/jmoyers/dev/narnia/node_modules/serverless/lib/cli/resolve-input.js:43:5
    at memoized (/Users/jmoyers/dev/narnia/node_modules/memoizee/lib/configure-map.js:80:41)
    at /Users/jmoyers/dev/narnia/node_modules/serverless/scripts/serverless.js:605:15
    at /Users/jmoyers/dev/narnia/node_modules/serverless/scripts/serverless.js:740:9

Use case is the following: I have a lambda layer I'd like to deploy as a service, and then several lambdas that I'd like to deploy in parallel that depend on the lambda layer. As a result, I'd like to use the layer arn as an output from one service to drive several others.

Later, I'd like to update the function code of one of the dependent lambdas, so I try to deploy via serverless deploy function -f {function name} -- but find that I need the lambda layer arn to be explicitly passed in as a parameter, or that I need to run it through the compose function instead. Trying to run it through the compose function, I get the above parsing error, presumably because the sub-command has "two parts" -- deploy + function.

pgrzesik commented 2 years ago

Hello @jmoyers, thanks for reporting and sorry you've run into trouble here. I've tried to reproduce your issue without running commands through yarn as in your case and commands like these

sls deploy function --service producer --function producer

worked correctly.

In order to help debugging, could you please paste the output of your command with --verbose enabled? Or paste the conents of .serverless/compose.log file after running your command?

In the meantime, you might try running the command with --service flag passed after the actual command - for Framework methods it's already enforced that options cannot appear before command and it will be the case for Compose commands in the future as well

jmoyers commented 2 years ago

Wohoo! That works. I'll go ahead and close.

r-token commented 2 years ago

Re-upping this:

I'm seeing the same Cannot convert undefined or null to object error message when deploying a specific function, but only when using the following syntax: sls {service}:deploy function -f {functionName}

If I use sls {service}:deploy function --function {functionName}, it works as expected.

pgrzesik commented 2 years ago

Thanks @r-token - I'll investigate this πŸ‘

pgrzesik commented 2 years ago

Hey @r-token - I didn't manage to reproduce your exact error message, but I've found that shorthand options such as -f <function> were not handled correctly. Could you share more about your specific case? What version of compose are you using?

The issue that I've discovered will be fixed with: https://github.com/serverless/compose/pull/118

r-token commented 2 years ago

Here's the output when running sls -v:

Running "serverless" from node_modules
Framework Core: 3.17.0 (local) 3.17.0 (global)
Plugin: 6.2.2
SDK: 4.3.2

The full error message I get back when using the -f shorthand looks like this:

Error:
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at resolveArgsSchema (/path-to-project-root/node_modules/serverless/lib/cli/resolve-input.js:13:45)
    at /path-to-project-root/node_modules/serverless/lib/cli/resolve-input.js:41:5
    at memoized (/path-to-project-root/node_modules/memoizee/lib/configure-map.js:80:41)
    at /path-to-project-root/node_modules/serverless/scripts/serverless.js:610:15
    at /path-to-project-root/node_modules/serverless/scripts/serverless.js:745:9
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
pgrzesik commented 2 years ago

I've just published v1.0.3 version of Compose, could you check if the problem still persists for you @r-token? Thanks in advance πŸ™‡

r-token commented 2 years ago

Updated to Compose v1.0.3 and it worked! Thank you @pgrzesik!