constructs icon indicating copy to clipboard operation
constructs copied to clipboard

Internal Server Error / Runtime.ExitError

Open connerdassen opened this issue 1 year ago • 2 comments

I cannot get this to work whatsoever, and because of a lack of logs I don't know where it's going wrong. I have a Laravel project that I want to deploy using the CDK like this:

this.backend = new PhpFpmFunction(this, `Backend-${STAGE}`, {
            handler: 'public/index.php',
            code: packagePhpCode('code/backend'),
            phpVersion: '8.3',
            vpc: props.vpc
}

It all deploys fine, but when visiting the resulting URL, I get an Internal Server Error, with the CloudWatch containins only this:

INIT_REPORT Init Duration: 404.55 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
START RequestId: dc4f6c9f-eee8-44d2-82ea-317cda3ac07b Version: $LATEST
RequestId: dc4f6c9f-eee8-44d2-82ea-317cda3ac07b Error: Runtime exited with error: exit status 255 Runtime.ExitError

No further useful info at all.

I tried debugging locally using docker and found out the same Runtime.ExitError happened there, which was due to not having bref/bref and bref/laravel-bridge installed.

However, after installing, the error went away locally, but it still happens on Lambda after redeploying. I did notice that when I download the code from lambda, the vendor directory only contains aws/ and autoload.php, not any of the dependencies. If I run locally on docker with only these present, I also get a Runtime.ExitError.

connerdassen avatar Mar 04 '24 02:03 connerdassen

It seems that missing packages in vendor are indeed the problem; something causes packagePhpCode to not include anything other than vendor/aws and vendor/autoload.php. After manually zipping and using lambda.Code.fromAsset, the lambda includes all packages in vendor and it works.

connerdassen avatar Mar 04 '24 02:03 connerdassen

It seems to still not work perfectly, the invocation itself succeeds now, but I'm getting a 500 internal server error response on any path. CloudFront now looks like this:

REPORT RequestId: 9902b69e-2126-4df7-89f9-e7f3603debab	Duration: 1.77 ms	Billed Duration: 2 ms	Memory Size: 1024 MB	Max Memory Used: 89 MB	
START RequestId: 5887e595-a18e-4193-9563-0441d6d35083 Version: $LATEST
[AWS Parameters and Secrets Lambda Extension] 2024/03/04 03:02:03 INFO ready to serve traffic
END RequestId: 5887e595-a18e-4193-9563-0441d6d35083

with no output from PHP or Laravel at all.

connerdassen avatar Mar 04 '24 03:03 connerdassen