Local development for functions

It is possible to run PHP functions locally.

To run web apps locally, see Local development for HTTP applications instead.

The vendor/bin/bref local command invokes your PHP functions locally. You can provide an event if your function expects one.

For example, given this function:

return function (array $event) {
    return 'Hello ' . ($event['name'] ?? 'world');
};
# ...

functions:
    hello:
        handler: my-function.php
        layers:
            - ${bref:layer.php-74}

You can invoke it with or without event data:

$ vendor/bin/bref local hello
Hello world

# With JSON event data
$ vendor/bin/bref local hello '{"name": "Jane"}'
Hello Jane

# With JSON in a file
$ vendor/bin/bref local hello --file=event.json
Hello Jane

The bref local command runs using the local PHP installation. If you prefer to run commands using the same environment as Lambda, you can use Docker.

Here is an example, feel free to adjust it to fit your needs:

docker run --rm -it -v $(PWD):/var/task:ro,delegated bref/php-74 vendor/bin/bref local hello

If you do not use serverless.yml but something else like SAM/CDK/CloudFormation/Terraform, use the --handler parameter instead:

$ vendor/bin/bref local --handler=my-function.php
Hello world

# With JSON event data
$ vendor/bin/bref local '{"name": "Jane"}' --handler=my-function.php
Hello Jane

# With JSON in a file
$ vendor/bin/bref local --handler=my-function.php --file=event.json
Hello Jane