Cron functions on AWS Lambda

AWS Lambda lets us run PHP functions as cron tasks using the schedule event:

functions:
    console:
        handler: function.php
        layers:
            - ${bref:layer.php-74}
        events:
            - schedule: rate(1 hour)

The example above will run the function returned by function.php every hour in AWS Lambda. For example:

<?php
require __DIR__ . '/vendor/autoload.php';

return function ($event) {
    echo 'My cron function is running!';
};

It is possible to provide data inside the $event variable via the input option:

    console:
        ...
        events:
            - schedule:
                  rate: rate(1 hour)
                  input:
                      foo: bar
                      Hello: World

Read more about the schedule feature in the Serverless documentation.

If you are interested in cron CLI commands instead, read the Cron commands documentation.