How to fix "HTTP header is larger than 10240 bytes." error on Laravel Vapor

When deploying applications with Laravel Vapor, you might encounter an error stating, "HTTP header is larger than 10240 bytes."

I first encountered this issue after deploying an application that used Filament, which I assume is due to filament storing various state about pagination and filter states in the session.

Since Laravel Vapor defaults to using the cookie session driver, all of this session data is passed back and forth in the HTTP Set-Cookie header, which can quickly grow to be larger than 10240 byte, which seems to be the upper limit for AWS Lambda for whatever reason.

Solution

To resolve this error, switch the session driver from cookie to either dynamodb, redis or database. This will significantly reduce the size of the HTTP headers since the session data will no longer be stored in cookies, and boom, our problem goes away.

How to Change the Session Driver

Edit your .env file and update the SESSION_DRIVER configuration:

SESSION_DRIVER=dynamodb

After making this change, deploy (or Redeploy) your application, and the error should be resolved.

Note: You might have to manually clear your cookies in your browser to get rid of the error message, so keep that in mind.