Symfony Dotenv->bootEnv() error
Hello all,
Since the new releases I'm encoutering issues with loading the environment variables, specifically with Symfony Dotenv.
By following this guide: https://bref.sh/docs/frameworks/symfony.html
The Lambda gives us the following errors:

Not sure why it's looking for the .env file but I assume it has something to do with the recent update on serverless .env file support. https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES
Hope this contributes.
Same here .env is not read by laravel when deployed using sls deploy
Thanks, it seems to be caused by https://github.com/serverless/serverless/pull/8634 (a change in serverless). I'll post a comment there.
If someone else is encountering this problem, you can simply downgrade serverless to 2.15.0 by running the following command and your application should be good to go again:
npm install -g [email protected]
If someone else is encountering this problem, you can simply downgrade serverless to 2.15.0 by running the following command and your application should be good to go again:
npm install -g [email protected]
Thank you for the quick workaround !
put this in your serverless.yml file
package: include: ".env*"
https://github.com/serverless/serverless/pull/8648#discussion_r546710547
Thanks to @mnapoli they are discussing the .env file as a need for the framework rather than its need for the lambda itself until then the above should work
I think https://github.com/serverless/serverless/pull/8648 solves this issue for now (you need to upgrade serverless), should we close this?
Seems fair right. Maybe update the documentation though?
Serverless 3 enable this behaviour and seems to force it. I had a deprecation saying that I could enable it now and so I did. In order to fix it I had to add a check.
bin/console & public/index.php
- (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
+ if (!isset($_SERVER['LAMBDA_TASK_ROOT'])) (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
I used the same thing than what's used for cache configuration in src/Kernel.php
Closing this issue: .env are no longer excluded by default in SF 3.