Laravel 6 - Internal server error with timeout
After following the tutorial provided here, Lambda is constantly returning 502:
{"message": "Internal server error"}
Serverless.yml
service: test
provider:
name: aws
region: sa-east-1
runtime: provided
environment:
APP_STORAGE: '/tmp'
plugins:
- ./vendor/bref/bref
package:
exclude:
- database/**
functions:
website:
handler: public/index.php
timeout: 28
layers:
- ${bref:layer.php-73-fpm}
events:
- http: 'ANY /'
- http: 'ANY /{proxy+}'
artisan:
handler: artisan
timeout: 120
layers:
- ${bref:layer.php-73}
- ${bref:layer.console}
CloudWatch logs:
[17-Oct-2019 14:14:05] NOTICE: fpm is running, pid 9
[17-Oct-2019 14:14:05] NOTICE: ready to handle connections
START RequestId: [truncated] Version: $LATEST
END RequestId: [truncated]
REPORT RequestId: [truncated] Duration: 28028.16 ms Billed Duration: 28400 ms Memory Size: 1024 MB Max Memory Used: 109 MB Init Duration: 328.48 ms
2019-10-17T14:14:33.300Z [truncated] Task timed out after 28.03 seconds
[17-Oct-2019 14:14:33] NOTICE: fpm is running, pid 8
[17-Oct-2019 14:14:33] NOTICE: ready to handle connections
START RequestId: [truncated] Version: $LATEST
END RequestId: [truncated]
REPORT RequestId: [truncated] Duration: 28024.07 ms Billed Duration: 28000 ms Memory Size: 1024 MB Max Memory Used: 42 MB
2019-10-17T14:15:10.456Z [truncated] Task timed out after 28.02 seconds
PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate.
START RequestId: [truncated] Version: $LATEST
[17-Oct-2019 14:15:36] NOTICE: fpm is running, pid 8
[17-Oct-2019 14:15:36] NOTICE: ready to handle connections
END RequestId: [truncated]
REPORT RequestId: [truncated] Duration: 28010.52 ms Billed Duration: 28000 ms Memory Size: 1024 MB Max Memory Used: 42 MB
2019-10-17T14:16:04.609Z [truncated] Task timed out after 28.01 seconds
PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate.
The code always timeouts, no output is provided anywhere, even forcing the app environment to debug.
I'm using the PostgreSQL extension shipped with Bref.
A common reason for a timeout like this is because the database connection times out after 30 seconds. If PHP can't connect to the DB, it will wait for 30 seconds. But the timeout of Lambda is 28seconds, so it will stop before that.
Anyway, make sure your DB connection is working. If you created a DB inside a VPC, you need to configure the lambda inside the VPC as well.
https://bref.sh/docs/environment/database.html can help.
@mnapoli It was my bad(kind of), even tough the RDS instance was set as publicly available the security groups where still blocked.