brefphp / bref

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

Enable file path to data on bref-local with CDK #1627

Closed theoboldalex closed 1 year ago

theoboldalex commented 1 year ago

This change provides command line access to the --path flag where an application is built on AWS CDK rather than Serverless framework. This enables the passing of a path to a JSON file when running vendor/bin/bref--local instead of passing data as a string.

If you agree with the premise of this change, I will also update the relevant documentation and include in the PR.

mnapoli commented 1 year ago

Hey, that sounds like a good idea. I'm not familiar with getopt, so I'm not sure what the command will look like. If you add docs that will probably be clearer to me 👍

theoboldalex commented 1 year ago

Great, I will work on the docs and update the PR in due course. Thanks

mnapoli commented 1 year ago

Thanks!

theoboldalex commented 1 year ago

I have had another look at this and think it might actually be better to match the way we invoke locally with the way we would if using Serverless.

Serverless serverless bref:local -f hello --path=event.json

CDK/TF vendor/bin/bref-local -f my-function.php --path event.json

If you think that is worth doing, I follow up with another PR.

Thanks

mnapoli commented 1 year ago

Sorry I'm missing what would be different with what you implemented?

theoboldalex commented 1 year ago

Apologies, I didn't explain very well above.

In the current implementation, when we pass the --path flag, it must be passed before the handler file.

When running Bref with Serverless, the handler file has the -f flag. I could add this to the non-Serverless bref-local script to ensure consistency in how functions are invoked locally regardless of whether we are using Serverless, CDK or Terraform.

mnapoli commented 1 year ago

Oh yes that would be great indeed, in most PHP CLIs (artisan, Symfony Console) that's how it works. If you can do that without pulling in more dependencies that would be a very good improvement 👍