phpamazon-web-servicessymfonyaws-lambdabref

How to stop PHPSESSID changing with AWS Lambda/CloudFront?


I have a PHP application hosted on AWS Lambda, written in Symfony using Bref.

I've managed to make all the functionaly work with serverless but I have one problem.

Users can log in, but if they navigate to another page they are effectively logged out again.

When I look at the cookes being set, it looks as though the issue is that PHPSESSID keeps changing.

Does anybody know how this can be overcome?

CloudFront is set to forward cookies but this doesn't seem to help.


Solution

  • It turns out I fundamentally misunderstood how AWS Lambda operates.

    @MisterSmith's comment was absolutely correct. By default, Symfony uses local file storage to manage sessions and because of the way Lambda works, these are essentially lost on each execution.

    There is the option to store sessions in the database, which I am now doing: https://symfony.com/doc/current/session.html#store-sessions-in-a-relational-database-mariadb-mysql-postgresql

    However, it is clear that AWS Lambda is not most suited for customer facing web applications. I have, instead, switched to using Elasticbeanstalk.

    I wanted to post the conclusion here in case anybody else is barking up the same tree.