As explained in the storage documentation, the filesystem on AWS Lambda is:
- read-only, except for
- not shared between lambda instances
- not persistent
Because of that, logs should not be stored on disk.
The simplest solution is to push logs to AWS CloudWatch, AWS' service for logs.
PHP errors and warnings
By default, all PHP errors, warnings and notices emitted by PHP will be forwarded into CloudWatch.
That means that you don't have to configure anything to log errors, warnings or uncaught exceptions.
Your application can write logs to CloudWatch:
- in a PHP function: write logs to
echofor example) or
- in a HTTP application: write logs to
For example with Monolog:
$log = new Monolog\Logger('name'); $log->pushHandler(new StreamHandler('php://stderr', Logger::WARNING)); $log->warning('This is a warning!');
For simple needs, you can replace Monolog with Bref's logger, a PSR-3 logger designed for AWS Lambda:
$log = new \Bref\Logger\StderrLogger(); $log->warning('This is a warning!');
To read logs, either open the CloudWatch console or open the Bref Dashboard by running
You can also use
serverless logs -f <function-name> # Tail logs: serverless logs -f <function-name> --tail
Advanced use cases
If you have more specific needs you can send logs to other services, for example Logstash, Papertrail, or Loggly.