Lambda ZIP function with Amazon Linux 2023 runtime fails

0

Hello.

I'm quite new with Lambda and I'm trying to run execute a PHP script with the FrankenPHP CLI. I'm doing so by having a bootstrap script that contains the following:

#!/bin/bash
set -e

./frankenphp-linux-x86_64 php-cli test.php 2>&1

My php script contains the following:

<?php $response = [
    'statusCode' => 200,
    'body' => json_encode(['message' => 'Success']),
    'headers' => ['Content-Type' => 'application/json']
];

echo json_encode($response);

I added the files along with the frankenphp-linux-x86_64 binary to a zip file and uploaded it to a Lambda function with the "Amazon Linux 2023" runtime. When testing the function, I get the following output:

/var/task/bootstrap: line 2:    10 Killed                  ./frankenphp-linux-x86_64 php-cli test.php
INIT_REPORT Init Duration: 812.48 ms    Phase: init    Status: error    Error Type: Runtime.ExitError
INIT_REPORT Init Duration: 3036.22 ms    Phase: invoke    Status: timeout
START RequestId: 2d28cbd3-2d0b-4170-9c47-04f89d1bb482 Version: $LATEST
2024-08-16T10:53:35.653Z 2d28cbd3-2d0b-4170-9c47-04f89d1bb482 Task timed out after 3.06 seconds

END RequestId: 2d28cbd3-2d0b-4170-9c47-04f89d1bb482
REPORT RequestId: 2d28cbd3-2d0b-4170-9c47-04f89d1bb482    Duration: 3056.45 ms    Billed Duration: 3000 ms    Memory Size: 128 MB    Max Memory Used: 45 MB    

I initially thought this was maybe because the binary couldn't run on the Amazon Linux 2023 runtime, but testing the bootstrap file locally in Docker it works fine:

$ docker run -it --rm -v $PWD:/app --entrypoint /bin/bash public.ecr.aws/lambda/provided:al2023                                                                                                                           [12:51:48]
bash-5.2# cd /app
bash-5.2# ./bootstrap
{"statusCode":200,"body":"{\"message\":\"Success\"}","headers":{"Content-Type":"application\/json"}}

I suspect that I might be misunderstanding something. Can you help me understand?

preguntada hace 2 meses169 visualizaciones
1 Respuesta
0

The last log message with says Task time out after 3.06 seconds is important here - the Lambda service terminated your task because it was running for three seconds. That's the default task timeout period - you can increase that and it would appear that your code needs to run for more than three seconds.

profile pictureAWS
EXPERTO
respondido hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas