1

I am running a Symfony 4 (PHP) application on AWS Lambda using Bref (which uses Serverless).

Bref provides a layer for Symfony's bin/console binary. The Serverless config for the Lambda function looks like this:

functions:
    console:
        handler: bin/console
        name: 'mm-console'
        description: 'Symfony 4 console'
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer

Using the above, I can run vendor/bin/bref cli mm-console -- mm:find-matches to run bin/console mm:find-matches on Lambda.

What if I want to run the mm:find-matches console command on a schedule on Lambda? I tried this:

functions:
    mm-find-matches:
        handler: "bin/console mm:find-matches"
        name: 'mm-find-matches'
        description: 'Find mentor matches'
        timeout: 120
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer
        schedule:
            rate: rate(2 hours)

However "bin/console mm:find-matches" is not a valid handler. How can I pass mm:find-matches command to the bin/console function on a schedule?

amacrobert
  • 2,707
  • 2
  • 28
  • 37

1 Answers1

2

You can pass command line arguments via the schedule event input like so:

functions:
    console:
        handler: bin/console
        name: 'mm-console'
        description: 'Symfony 4 console'
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-73} # PHP
            - ${bref:layer.console} # The "console" layer
        events:
            - schedule:
                input:
                    cli: "mm:find-matches --env=test"
                rate: rate(2 hours)
                enabled: true

Although there is some discussion on this bref github issue about whether using the cli console application is the best solution, vs writing PHP functions that bootstrap the kernel and do the specific thing you want the command to do.

amacrobert
  • 2,707
  • 2
  • 28
  • 37