brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.15k stars 365 forks source link

More than one function contains the console layer: cannot automatically run it #1459

Closed ddeboer closed 1 year ago

ddeboer commented 1 year ago

Description:

If you have two or more functions using the console layer, for example a console and a cron function, Bref 2 throws an error when invoking bref:cli:

More than one function contains the console layer: cannot automatically run it

I didn’t find a way to manually provide the function name, as was used on Bref 1.

How to reproduce:

Configure at least two functions using the console layer, for example:

functions:
  console:
    handler: bin/console
    runtime: php-82-console  
  cron:
    handler: bin/console
    runtime: php-82-console

Then run:

$ serverless bref:cli
Running "serverless" from node_modules
Environment: darwin, node 18.14.1, framework 3.26.0 (local) 3.27.0v (global), plugin 6.2.2, SDK 4.3.2
Credentials: Local
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
More than one function contains the console layer: cannot automatically run it
t-richard commented 1 year ago

This is a current limitation of the bref:cli command.

To work around that, you can use serverless invoke directly, see this for the used options https://github.com/brefphp/bref/blob/651523ecfef982ba5d2299f5580b39b400c1a617/plugin/run-console.js#L7-L12

Maybe the current command could support a --function option in case there are multiple console functions available

ddeboer commented 1 year ago

Maybe the current command could support a --function option in case there are multiple console functions available

Yep, that would be the simplest solution.

t-richard commented 1 year ago

It should be easy to contribute if you can to give it a try

mnapoli commented 1 year ago

😄 I honestly thought it would be a very rare scenario, so I didn't plan for this in the v2 release. I wasn't expecting this to come up so fast :D

Maybe the current command could support a --function option in case there are multiple console functions available

Sounds perfect!

mnapoli commented 1 year ago

oh wow, the PR is here already ❤️

ddeboer commented 1 year ago

Yep, long live open source. 😄

Out of curiosity: why did you consider this scenario rare? I would expect more users to have both a console and a cron/schedule function that invokes CLI commands, for example when using a framework like Symfony.

mnapoli commented 1 year ago

Out of curiosity: why did you consider this scenario rare? I would expect more users to have both a console and a cron/schedule function that invokes CLI commands, for example when using a framework like Symfony.

That makes a lot of sense… I use one for both, but I could totally see how one would want to separate them!