Logs
As explained in the storage documentation, the filesystem on AWS Lambda is:
- read-only, except for
/tmp
- not shared between lambda instances
- not persistent
Because of that, logs should not be stored on disk.
CloudWatch
Instead of storing logs on disk, logs should be pushed to AWS CloudWatch (opens in a new tab), AWS' service for logs.
Writing logs
By default, Bref will forward low-level PHP errors and warnings to CloudWatch.
For all other logs, your application should write logs to CloudWatch:
- With the PHP-FPM runtime for web apps: write logs to
stderr
- With the runtime for event-driven functions: write logs to
stdout
(usingecho
for example) orstderr
AWS Lambda has a built-in mechanism to forward logs written to stderr
(or stdout
for event-driven functions) to CloudWatch Logs in the background, without performance impact.
If you use Laravel, Bref will automatically configure Laravel to log to CloudWatch via stderr
(LOG_CHANNEL=stderr
). You don't have to do anything.
If you have a custom log setup (e.g. using the stack
channel), you should ensure that the stderr
channel is included in your stack.
It is also recommended you enable Bref's logs formatter optimized for CloudWatch:
provider:
environment:
LOG_STDERR_FORMATTER: Bref\Monolog\CloudWatchFormatter
This formatter will be enabled by default in Bref v3.
With this formatter, logs will contain structured data that can be filtered in CloudWatch Logs Insights. For example, you can filter by log level, exception class, or anything in the Laravel Context (opens in a new tab).
Reading logs
You can view, search and tail logs in the Bref Cloud (opens in a new tab) dashboard:

If you don't use Bref Cloud, you can view logs in the CloudWatch console (opens in a new tab).
You can also use serverless logs
to view them in the terminal:
serverless logs -f <function-name>
# Tail logs:
serverless logs -f <function-name> --tail