From c4c77ac14afb1344de7f3c419abfa6ed02ba90cf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:03:21 +0000 Subject: [PATCH 1/7] Update layer versions --- layers.json | 670 ++++++++++++++++++++++++++-------------------------- 1 file changed, 335 insertions(+), 335 deletions(-) diff --git a/layers.json b/layers.json index c3db509b1..f365ced4a 100644 --- a/layers.json +++ b/layers.json @@ -1,115 +1,139 @@ { "php-83": { - "ca-central-1": "2", - "eu-central-1": "2", - "eu-north-1": "2", - "eu-west-1": "2", - "eu-west-2": "2", - "eu-west-3": "2", - "sa-east-1": "2", - "us-east-1": "2", - "us-east-2": "2", - "us-west-1": "2", - "us-west-2": "2", - "ap-east-1": "2", - "ap-south-1": "2", - "ap-northeast-1": "2", - "ap-northeast-2": "2", - "ap-northeast-3": "2", - "ap-southeast-1": "2", - "ap-southeast-2": "2", - "eu-south-1": "2", - "eu-south-2": "2", - "af-south-1": "2", - "me-south-1": "2" + "ca-central-1": "3", + "eu-central-1": "3", + "eu-north-1": "3", + "eu-west-1": "3", + "eu-west-2": "3", + "eu-west-3": "3", + "sa-east-1": "3", + "us-east-1": "3", + "us-east-2": "3", + "us-west-1": "3", + "us-west-2": "3", + "ap-east-1": "3", + "ap-south-1": "3", + "ap-northeast-1": "3", + "ap-northeast-2": "3", + "ap-northeast-3": "3", + "ap-southeast-1": "3", + "ap-southeast-2": "3", + "eu-south-1": "3", + "eu-south-2": "3", + "af-south-1": "3", + "me-south-1": "3" }, "php-83-fpm": { - "ca-central-1": "2", - "eu-central-1": "2", - "eu-north-1": "2", - "eu-west-1": "2", - "eu-west-2": "2", - "eu-west-3": "2", - "sa-east-1": "2", - "us-east-1": "2", - "us-east-2": "2", - "us-west-1": "2", - "us-west-2": "2", - "ap-east-1": "2", - "ap-south-1": "2", - "ap-northeast-1": "2", - "ap-northeast-2": "2", - "ap-northeast-3": "2", - "ap-southeast-1": "2", - "ap-southeast-2": "2", - "eu-south-1": "2", - "eu-south-2": "2", - "af-south-1": "2", - "me-south-1": "2" + "ca-central-1": "3", + "eu-central-1": "3", + "eu-north-1": "3", + "eu-west-1": "3", + "eu-west-2": "3", + "eu-west-3": "3", + "sa-east-1": "3", + "us-east-1": "3", + "us-east-2": "3", + "us-west-1": "3", + "us-west-2": "3", + "ap-east-1": "3", + "ap-south-1": "3", + "ap-northeast-1": "3", + "ap-northeast-2": "3", + "ap-northeast-3": "3", + "ap-southeast-1": "3", + "ap-southeast-2": "3", + "eu-south-1": "3", + "eu-south-2": "3", + "af-south-1": "3", + "me-south-1": "3" }, "php-82": { - "ca-central-1": "46", - "eu-central-1": "46", - "eu-north-1": "46", - "eu-west-1": "46", - "eu-west-2": "46", - "eu-west-3": "46", - "sa-east-1": "46", - "us-east-1": "46", - "us-east-2": "46", - "us-west-1": "46", - "us-west-2": "46", - "ap-east-1": "46", - "ap-south-1": "46", - "ap-northeast-1": "46", - "ap-northeast-2": "46", - "ap-northeast-3": "46", - "ap-southeast-1": "46", - "ap-southeast-2": "46", - "eu-south-1": "46", - "eu-south-2": "45", - "af-south-1": "46", - "me-south-1": "46" + "ca-central-1": "47", + "eu-central-1": "47", + "eu-north-1": "47", + "eu-west-1": "47", + "eu-west-2": "47", + "eu-west-3": "47", + "sa-east-1": "47", + "us-east-1": "47", + "us-east-2": "47", + "us-west-1": "47", + "us-west-2": "47", + "ap-east-1": "47", + "ap-south-1": "47", + "ap-northeast-1": "47", + "ap-northeast-2": "47", + "ap-northeast-3": "47", + "ap-southeast-1": "47", + "ap-southeast-2": "47", + "eu-south-1": "47", + "eu-south-2": "46", + "af-south-1": "47", + "me-south-1": "47" }, "php-82-fpm": { - "ca-central-1": "46", - "eu-central-1": "46", - "eu-north-1": "46", - "eu-west-1": "46", - "eu-west-2": "46", - "eu-west-3": "46", - "sa-east-1": "46", - "us-east-1": "46", - "us-east-2": "46", - "us-west-1": "46", - "us-west-2": "46", - "ap-east-1": "46", - "ap-south-1": "46", - "ap-northeast-1": "46", - "ap-northeast-2": "46", - "ap-northeast-3": "46", - "ap-southeast-1": "46", - "ap-southeast-2": "46", - "eu-south-1": "46", - "eu-south-2": "45", - "af-south-1": "46", - "me-south-1": "46" + "ca-central-1": "47", + "eu-central-1": "47", + "eu-north-1": "47", + "eu-west-1": "47", + "eu-west-2": "47", + "eu-west-3": "47", + "sa-east-1": "47", + "us-east-1": "47", + "us-east-2": "47", + "us-west-1": "47", + "us-west-2": "47", + "ap-east-1": "47", + "ap-south-1": "47", + "ap-northeast-1": "47", + "ap-northeast-2": "47", + "ap-northeast-3": "47", + "ap-southeast-1": "47", + "ap-southeast-2": "47", + "eu-south-1": "47", + "eu-south-2": "46", + "af-south-1": "47", + "me-south-1": "47" }, "php-81": { + "ca-central-1": "58", + "eu-central-1": "58", + "eu-north-1": "58", + "eu-west-1": "58", + "eu-west-2": "58", + "eu-west-3": "58", + "sa-east-1": "58", + "us-east-1": "58", + "us-east-2": "58", + "us-west-1": "58", + "us-west-2": "58", + "ap-east-1": "50", + "ap-south-1": "57", + "ap-northeast-1": "57", + "ap-northeast-2": "57", + "ap-northeast-3": "57", + "ap-southeast-1": "57", + "ap-southeast-2": "57", + "eu-south-1": "50", + "eu-south-2": "47", + "af-south-1": "50", + "me-south-1": "50" + }, + "php-81-fpm": { "ca-central-1": "57", "eu-central-1": "57", - "eu-north-1": "57", - "eu-west-1": "57", + "eu-north-1": "58", + "eu-west-1": "58", "eu-west-2": "57", "eu-west-3": "57", "sa-east-1": "57", - "us-east-1": "57", + "us-east-1": "58", "us-east-2": "57", "us-west-1": "57", - "us-west-2": "57", - "ap-east-1": "49", + "us-west-2": "58", + "ap-east-1": "50", "ap-south-1": "56", - "ap-northeast-1": "56", + "ap-northeast-1": "57", "ap-northeast-2": "56", "ap-northeast-3": "56", "ap-southeast-1": "56", @@ -119,292 +143,268 @@ "af-south-1": "49", "me-south-1": "49" }, - "php-81-fpm": { - "ca-central-1": "56", - "eu-central-1": "56", - "eu-north-1": "57", - "eu-west-1": "57", - "eu-west-2": "56", - "eu-west-3": "56", - "sa-east-1": "56", - "us-east-1": "57", - "us-east-2": "56", - "us-west-1": "56", - "us-west-2": "57", - "ap-east-1": "49", - "ap-south-1": "55", - "ap-northeast-1": "56", - "ap-northeast-2": "55", - "ap-northeast-3": "55", - "ap-southeast-1": "55", - "ap-southeast-2": "55", - "eu-south-1": "48", - "eu-south-2": "45", - "af-south-1": "48", - "me-south-1": "48" - }, "php-80": { - "ca-central-1": "60", - "eu-central-1": "59", - "eu-north-1": "60", - "eu-west-1": "60", - "eu-west-2": "60", - "eu-west-3": "60", - "sa-east-1": "60", - "us-east-1": "60", - "us-east-2": "60", - "us-west-1": "60", - "us-west-2": "60", + "ca-central-1": "61", + "eu-central-1": "60", + "eu-north-1": "61", + "eu-west-1": "61", + "eu-west-2": "61", + "eu-west-3": "61", + "sa-east-1": "61", + "us-east-1": "61", + "us-east-2": "61", + "us-west-1": "61", + "us-west-2": "61", + "ap-east-1": "51", + "ap-south-1": "60", + "ap-northeast-1": "58", + "ap-northeast-2": "57", + "ap-northeast-3": "58", + "ap-southeast-1": "57", + "ap-southeast-2": "59", + "eu-south-1": "51", + "eu-south-2": "47", + "af-south-1": "51", + "me-south-1": "51" + }, + "php-80-fpm": { + "ca-central-1": "58", + "eu-central-1": "58", + "eu-north-1": "58", + "eu-west-1": "58", + "eu-west-2": "58", + "eu-west-3": "58", + "sa-east-1": "58", + "us-east-1": "58", + "us-east-2": "58", + "us-west-1": "58", + "us-west-2": "58", "ap-east-1": "50", - "ap-south-1": "59", + "ap-south-1": "57", "ap-northeast-1": "57", - "ap-northeast-2": "56", + "ap-northeast-2": "57", "ap-northeast-3": "57", - "ap-southeast-1": "56", - "ap-southeast-2": "58", + "ap-southeast-1": "57", + "ap-southeast-2": "57", "eu-south-1": "50", - "eu-south-2": "46", + "eu-south-2": "47", "af-south-1": "50", "me-south-1": "50" }, - "php-80-fpm": { - "ca-central-1": "57", - "eu-central-1": "57", - "eu-north-1": "57", - "eu-west-1": "57", - "eu-west-2": "57", - "eu-west-3": "57", - "sa-east-1": "57", - "us-east-1": "57", - "us-east-2": "57", - "us-west-1": "57", - "us-west-2": "57", - "ap-east-1": "49", - "ap-south-1": "56", - "ap-northeast-1": "56", - "ap-northeast-2": "56", - "ap-northeast-3": "56", - "ap-southeast-1": "56", - "ap-southeast-2": "56", - "eu-south-1": "49", - "eu-south-2": "46", - "af-south-1": "49", - "me-south-1": "49" - }, "arm-php-83": { - "ca-central-1": "2", - "eu-central-1": "2", - "eu-north-1": "2", - "eu-west-1": "2", - "eu-west-2": "2", - "eu-west-3": "2", - "sa-east-1": "2", - "us-east-1": "2", - "us-east-2": "2", - "us-west-1": "2", - "us-west-2": "2", - "ap-east-1": "2", - "ap-south-1": "2", - "ap-northeast-1": "2", - "ap-northeast-2": "2", - "ap-northeast-3": "2", - "ap-southeast-1": "2", - "ap-southeast-2": "2", - "eu-south-1": "2", - "eu-south-2": "2", - "af-south-1": "2", - "me-south-1": "2" + "ca-central-1": "3", + "eu-central-1": "3", + "eu-north-1": "3", + "eu-west-1": "3", + "eu-west-2": "3", + "eu-west-3": "3", + "sa-east-1": "3", + "us-east-1": "3", + "us-east-2": "3", + "us-west-1": "3", + "us-west-2": "3", + "ap-east-1": "3", + "ap-south-1": "3", + "ap-northeast-1": "3", + "ap-northeast-2": "3", + "ap-northeast-3": "3", + "ap-southeast-1": "3", + "ap-southeast-2": "3", + "eu-south-1": "3", + "eu-south-2": "3", + "af-south-1": "3", + "me-south-1": "3" }, "arm-php-83-fpm": { - "ca-central-1": "2", - "eu-central-1": "2", - "eu-north-1": "2", - "eu-west-1": "2", - "eu-west-2": "2", - "eu-west-3": "2", - "sa-east-1": "2", - "us-east-1": "2", - "us-east-2": "2", - "us-west-1": "2", - "us-west-2": "2", - "ap-east-1": "2", - "ap-south-1": "2", - "ap-northeast-1": "2", - "ap-northeast-2": "2", - "ap-northeast-3": "2", - "ap-southeast-1": "2", - "ap-southeast-2": "2", - "eu-south-1": "2", - "eu-south-2": "2", - "af-south-1": "2", - "me-south-1": "2" + "ca-central-1": "3", + "eu-central-1": "3", + "eu-north-1": "3", + "eu-west-1": "3", + "eu-west-2": "3", + "eu-west-3": "3", + "sa-east-1": "3", + "us-east-1": "3", + "us-east-2": "3", + "us-west-1": "3", + "us-west-2": "3", + "ap-east-1": "3", + "ap-south-1": "3", + "ap-northeast-1": "3", + "ap-northeast-2": "3", + "ap-northeast-3": "3", + "ap-southeast-1": "3", + "ap-southeast-2": "3", + "eu-south-1": "3", + "eu-south-2": "3", + "af-south-1": "3", + "me-south-1": "3" }, "arm-php-82": { - "ca-central-1": "34", - "eu-central-1": "34", - "eu-north-1": "34", - "eu-west-1": "34", - "eu-west-2": "34", - "eu-west-3": "34", - "sa-east-1": "34", - "us-east-1": "34", - "us-east-2": "34", - "us-west-1": "34", - "us-west-2": "34", - "ap-east-1": "34", - "ap-south-1": "34", - "ap-northeast-1": "34", - "ap-northeast-2": "34", - "ap-northeast-3": "34", - "ap-southeast-1": "34", - "ap-southeast-2": "34", - "eu-south-1": "34", - "eu-south-2": "34", - "af-south-1": "34", - "me-south-1": "34" + "ca-central-1": "35", + "eu-central-1": "35", + "eu-north-1": "35", + "eu-west-1": "35", + "eu-west-2": "35", + "eu-west-3": "35", + "sa-east-1": "35", + "us-east-1": "35", + "us-east-2": "35", + "us-west-1": "35", + "us-west-2": "35", + "ap-east-1": "35", + "ap-south-1": "35", + "ap-northeast-1": "35", + "ap-northeast-2": "35", + "ap-northeast-3": "35", + "ap-southeast-1": "35", + "ap-southeast-2": "35", + "eu-south-1": "35", + "eu-south-2": "35", + "af-south-1": "35", + "me-south-1": "35" }, "arm-php-82-fpm": { - "ca-central-1": "34", - "eu-central-1": "34", - "eu-north-1": "34", - "eu-west-1": "34", - "eu-west-2": "34", - "eu-west-3": "34", - "sa-east-1": "34", - "us-east-1": "34", - "us-east-2": "34", - "us-west-1": "34", - "us-west-2": "34", - "ap-east-1": "34", - "ap-south-1": "34", - "ap-northeast-1": "34", - "ap-northeast-2": "34", - "ap-northeast-3": "34", - "ap-southeast-1": "34", - "ap-southeast-2": "34", - "eu-south-1": "34", - "eu-south-2": "34", - "af-south-1": "34", - "me-south-1": "34" + "ca-central-1": "35", + "eu-central-1": "35", + "eu-north-1": "35", + "eu-west-1": "35", + "eu-west-2": "35", + "eu-west-3": "35", + "sa-east-1": "35", + "us-east-1": "35", + "us-east-2": "35", + "us-west-1": "35", + "us-west-2": "35", + "ap-east-1": "35", + "ap-south-1": "35", + "ap-northeast-1": "35", + "ap-northeast-2": "35", + "ap-northeast-3": "35", + "ap-southeast-1": "35", + "ap-southeast-2": "35", + "eu-south-1": "35", + "eu-south-2": "35", + "af-south-1": "35", + "me-south-1": "35" }, "arm-php-81": { - "ca-central-1": "37", - "eu-central-1": "37", - "eu-north-1": "37", - "eu-west-1": "37", - "eu-west-2": "37", - "eu-west-3": "37", - "sa-east-1": "37", - "us-east-1": "37", - "us-east-2": "37", - "us-west-1": "37", - "us-west-2": "37", - "ap-east-1": "37", - "ap-south-1": "37", - "ap-northeast-1": "37", - "ap-northeast-2": "37", - "ap-northeast-3": "37", - "ap-southeast-1": "37", - "ap-southeast-2": "37", - "eu-south-1": "37", - "eu-south-2": "37", - "af-south-1": "37", - "me-south-1": "37" + "ca-central-1": "38", + "eu-central-1": "38", + "eu-north-1": "38", + "eu-west-1": "38", + "eu-west-2": "38", + "eu-west-3": "38", + "sa-east-1": "38", + "us-east-1": "38", + "us-east-2": "38", + "us-west-1": "38", + "us-west-2": "38", + "ap-east-1": "38", + "ap-south-1": "38", + "ap-northeast-1": "38", + "ap-northeast-2": "38", + "ap-northeast-3": "38", + "ap-southeast-1": "38", + "ap-southeast-2": "38", + "eu-south-1": "38", + "eu-south-2": "38", + "af-south-1": "38", + "me-south-1": "38" }, "arm-php-81-fpm": { - "ca-central-1": "37", - "eu-central-1": "37", - "eu-north-1": "37", - "eu-west-1": "37", - "eu-west-2": "37", - "eu-west-3": "37", - "sa-east-1": "37", - "us-east-1": "37", - "us-east-2": "37", - "us-west-1": "37", - "us-west-2": "37", - "ap-east-1": "37", - "ap-south-1": "37", - "ap-northeast-1": "37", - "ap-northeast-2": "37", - "ap-northeast-3": "37", - "ap-southeast-1": "37", - "ap-southeast-2": "37", - "eu-south-1": "37", - "eu-south-2": "37", - "af-south-1": "37", - "me-south-1": "37" + "ca-central-1": "38", + "eu-central-1": "38", + "eu-north-1": "38", + "eu-west-1": "38", + "eu-west-2": "38", + "eu-west-3": "38", + "sa-east-1": "38", + "us-east-1": "38", + "us-east-2": "38", + "us-west-1": "38", + "us-west-2": "38", + "ap-east-1": "38", + "ap-south-1": "38", + "ap-northeast-1": "38", + "ap-northeast-2": "38", + "ap-northeast-3": "38", + "ap-southeast-1": "38", + "ap-southeast-2": "38", + "eu-south-1": "38", + "eu-south-2": "38", + "af-south-1": "38", + "me-south-1": "38" }, "arm-php-80": { + "ca-central-1": "60", + "eu-central-1": "59", + "eu-north-1": "60", + "eu-west-1": "60", + "eu-west-2": "60", + "eu-west-3": "60", + "sa-east-1": "60", + "us-east-1": "60", + "us-east-2": "60", + "us-west-1": "60", + "us-west-2": "60", + "ap-east-1": "52", + "ap-south-1": "59", + "ap-northeast-1": "59", + "ap-northeast-2": "59", + "ap-northeast-3": "59", + "ap-southeast-1": "59", + "ap-southeast-2": "59", + "eu-south-1": "52", + "eu-south-2": "48", + "af-south-1": "52", + "me-south-1": "52" + }, + "arm-php-80-fpm": { "ca-central-1": "59", "eu-central-1": "58", "eu-north-1": "59", "eu-west-1": "59", - "eu-west-2": "59", - "eu-west-3": "59", - "sa-east-1": "59", + "eu-west-2": "58", + "eu-west-3": "58", + "sa-east-1": "58", "us-east-1": "59", "us-east-2": "59", - "us-west-1": "59", + "us-west-1": "58", "us-west-2": "59", "ap-east-1": "51", - "ap-south-1": "58", + "ap-south-1": "57", "ap-northeast-1": "58", - "ap-northeast-2": "58", - "ap-northeast-3": "58", - "ap-southeast-1": "58", - "ap-southeast-2": "58", - "eu-south-1": "51", + "ap-northeast-2": "57", + "ap-northeast-3": "57", + "ap-southeast-1": "57", + "ap-southeast-2": "57", + "eu-south-1": "50", "eu-south-2": "47", "af-south-1": "51", - "me-south-1": "51" + "me-south-1": "50" }, - "arm-php-80-fpm": { - "ca-central-1": "58", + "console": { + "ca-central-1": "57", "eu-central-1": "57", - "eu-north-1": "58", - "eu-west-1": "58", + "eu-north-1": "57", + "eu-west-1": "57", "eu-west-2": "57", "eu-west-3": "57", "sa-east-1": "57", - "us-east-1": "58", - "us-east-2": "58", + "us-east-1": "57", + "us-east-2": "57", "us-west-1": "57", - "us-west-2": "58", - "ap-east-1": "50", + "us-west-2": "57", + "ap-east-1": "49", "ap-south-1": "56", - "ap-northeast-1": "57", + "ap-northeast-1": "56", "ap-northeast-2": "56", "ap-northeast-3": "56", "ap-southeast-1": "56", "ap-southeast-2": "56", "eu-south-1": "49", "eu-south-2": "46", - "af-south-1": "50", + "af-south-1": "49", "me-south-1": "49" - }, - "console": { - "ca-central-1": "56", - "eu-central-1": "56", - "eu-north-1": "56", - "eu-west-1": "56", - "eu-west-2": "56", - "eu-west-3": "56", - "sa-east-1": "56", - "us-east-1": "56", - "us-east-2": "56", - "us-west-1": "56", - "us-west-2": "56", - "ap-east-1": "48", - "ap-south-1": "55", - "ap-northeast-1": "55", - "ap-northeast-2": "55", - "ap-northeast-3": "55", - "ap-southeast-1": "55", - "ap-southeast-2": "55", - "eu-south-1": "48", - "eu-south-2": "45", - "af-south-1": "48", - "me-south-1": "48" } } \ No newline at end of file From 570629f8cb73b4f4a2efb0cfcd740aa0d59a4637 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 11:39:22 +0200 Subject: [PATCH 2/7] Fix #1520 "Unknown application error occurred Runtime.Unknown" --- src/FunctionRuntime/Main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FunctionRuntime/Main.php b/src/FunctionRuntime/Main.php index c4843eda4..2509a51f0 100644 --- a/src/FunctionRuntime/Main.php +++ b/src/FunctionRuntime/Main.php @@ -25,7 +25,7 @@ public static function run(): void try { $handler = $container->get(getenv('_HANDLER')); } catch (Throwable $e) { - $lambdaRuntime->failInitialization($e->getMessage()); + $lambdaRuntime->failInitialization($e->getMessage(), $e); } $loopMax = getenv('BREF_LOOP_MAX') ?: 1; From d1ce4261ed08e53716994d76f216f43ffce502d7 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 12:12:59 +0200 Subject: [PATCH 3/7] Improve Lambda initialization errors --- src/ConsoleRuntime/Main.php | 2 +- src/FpmRuntime/Main.php | 5 +++-- src/FunctionRuntime/Main.php | 2 +- src/Runtime/LambdaRuntime.php | 37 ++++++++++++++++++++++------------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/ConsoleRuntime/Main.php b/src/ConsoleRuntime/Main.php index d42435b55..b5c3bbeeb 100755 --- a/src/ConsoleRuntime/Main.php +++ b/src/ConsoleRuntime/Main.php @@ -25,7 +25,7 @@ public static function run(): void $appRoot = getenv('LAMBDA_TASK_ROOT'); $handlerFile = $appRoot . '/' . getenv('_HANDLER'); if (! is_file($handlerFile)) { - $lambdaRuntime->failInitialization("Handler `$handlerFile` doesn't exist"); + $lambdaRuntime->failInitialization("Handler `$handlerFile` doesn't exist", 'Runtime.NoSuchHandler'); } /** @phpstan-ignore-next-line */ diff --git a/src/FpmRuntime/Main.php b/src/FpmRuntime/Main.php index 6c8aa842b..d3241b5d1 100755 --- a/src/FpmRuntime/Main.php +++ b/src/FpmRuntime/Main.php @@ -5,6 +5,7 @@ use Bref\Bref; use Bref\LazySecretsLoader; use Bref\Runtime\LambdaRuntime; +use RuntimeException; use Throwable; /** @@ -27,14 +28,14 @@ public static function run(): void $appRoot = getenv('LAMBDA_TASK_ROOT'); $handlerFile = $appRoot . '/' . getenv('_HANDLER'); if (! is_file($handlerFile)) { - $lambdaRuntime->failInitialization("Handler `$handlerFile` doesn't exist"); + $lambdaRuntime->failInitialization("Handler `$handlerFile` doesn't exist", 'Runtime.NoSuchHandler'); } $phpFpm = new FpmHandler($handlerFile); try { $phpFpm->start(); } catch (Throwable $e) { - $lambdaRuntime->failInitialization('Error while starting PHP-FPM', $e); + $lambdaRuntime->failInitialization(new RuntimeException('Error while starting PHP-FPM: ' . $e->getMessage(), 0, $e)); } /** @phpstan-ignore-next-line */ diff --git a/src/FunctionRuntime/Main.php b/src/FunctionRuntime/Main.php index 2509a51f0..f6925ca06 100644 --- a/src/FunctionRuntime/Main.php +++ b/src/FunctionRuntime/Main.php @@ -25,7 +25,7 @@ public static function run(): void try { $handler = $container->get(getenv('_HANDLER')); } catch (Throwable $e) { - $lambdaRuntime->failInitialization($e->getMessage(), $e); + $lambdaRuntime->failInitialization($e, 'Runtime.NoSuchHandler'); } $loopMax = getenv('BREF_LOOP_MAX') ?: 1; diff --git a/src/Runtime/LambdaRuntime.php b/src/Runtime/LambdaRuntime.php index 6fbadb316..a409d1eee 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -237,44 +237,52 @@ private function signalFailure(string $invocationId, Throwable $error): void /** * Abort the lambda and signal to the runtime API that we failed to initialize this instance. * + * @param 'Runtime.NoSuchHandler'|'Runtime.UnknownReason' $lambdaInitializationReason + * * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-initerror * * @phpstan-return never-returns */ - public function failInitialization(string $message, ?Throwable $error = null): void + public function failInitialization(string|Throwable $error, $lambdaInitializationReason = 'Runtime.UnknownReason'): void { // Log the exception in CloudWatch - echo "$message\n"; - if ($error) { - if ($error instanceof Exception) { - $errorMessage = get_class($error) . ': ' . $error->getMessage(); - } else { - $errorMessage = $error->getMessage(); - } + if ($error instanceof Throwable) { + $data = [ + 'errorMessage' => $error->getMessage(), + 'errorType' => get_class($error), + 'stackTrace' => explode(PHP_EOL, $error->getTraceAsString()), + ]; printf( "Fatal error: %s in %s:%d\nStack trace:\n%s", - $errorMessage, + get_class($error) . ': ' . $error->getMessage(), $error->getFile(), $error->getLine(), $error->getTraceAsString() ); + } else { + $data = [ + 'errorMessage' => $error, + 'errorType' => 'Internal', + 'stackTrace' => [], + ]; + echo "$error\n"; } $url = "http://$this->apiUrl/2018-06-01/runtime/init/error"; - $this->postJson($url, [ - 'errorMessage' => $message . ' ' . ($error ? $error->getMessage() : ''), - 'errorType' => $error ? get_class($error) : 'Internal', - 'stackTrace' => $error ? explode(PHP_EOL, $error->getTraceAsString()) : [], + $this->postJson($url, $data, [ + "Lambda-Runtime-Function-Error-Type: $lambdaInitializationReason", ]); exit(1); } /** + * @param string[] $headers + * * @throws ResponseTooBig * @throws Exception */ - private function postJson(string $url, mixed $data): void + private function postJson(string $url, mixed $data, array $headers = []): void { /** @noinspection JsonEncodingApiUsageInspection */ $jsonData = json_encode($data); @@ -296,6 +304,7 @@ private function postJson(string $url, mixed $data): void curl_setopt($this->curlHandleResult, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($jsonData), + ...$headers ]); $body = curl_exec($this->curlHandleResult); From 434ffd4bbeddf52b21cd97a6cda07573cc7e1281 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 14:12:48 +0200 Subject: [PATCH 4/7] Improve Lambda initialization error logs --- src/Runtime/LambdaRuntime.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Runtime/LambdaRuntime.php b/src/Runtime/LambdaRuntime.php index a409d1eee..7bb089f3b 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -268,6 +268,8 @@ public function failInitialization(string|Throwable $error, $lambdaInitializatio echo "$error\n"; } + echo "The function failed to start. AWS Lambda will restart the process, do not be surprised if you see the error message twice.\n"; + $url = "http://$this->apiUrl/2018-06-01/runtime/init/error"; $this->postJson($url, $data, [ "Lambda-Runtime-Function-Error-Type: $lambdaInitializationReason", From e042ba80f5881cfa5b9042213caa3e7dfb31d004 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 14:18:16 +0200 Subject: [PATCH 5/7] Add JSON data to initialization error logs --- src/Runtime/LambdaRuntime.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Runtime/LambdaRuntime.php b/src/Runtime/LambdaRuntime.php index 7bb089f3b..96b3a7996 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -243,21 +243,28 @@ private function signalFailure(string $invocationId, Throwable $error): void * * @phpstan-return never-returns */ - public function failInitialization(string|Throwable $error, $lambdaInitializationReason = 'Runtime.UnknownReason'): void - { + public function failInitialization( + string|Throwable $error, + string $lambdaInitializationReason = 'Runtime.UnknownReason', + ): void { // Log the exception in CloudWatch if ($error instanceof Throwable) { + $traceAsArray = explode(PHP_EOL, $error->getTraceAsString()); $data = [ 'errorMessage' => $error->getMessage(), 'errorType' => get_class($error), - 'stackTrace' => explode(PHP_EOL, $error->getTraceAsString()), + 'stackTrace' => $traceAsArray, ]; printf( - "Fatal error: %s in %s:%d\nStack trace:\n%s", + "Fatal error: %s in %s:%d\n %s\n", get_class($error) . ': ' . $error->getMessage(), $error->getFile(), $error->getLine(), - $error->getTraceAsString() + json_encode([ + 'message' => $error->getMessage(), + 'type' => get_class($error), + 'stackTrace' => $traceAsArray, + ], JSON_THROW_ON_ERROR), ); } else { $data = [ @@ -265,7 +272,7 @@ public function failInitialization(string|Throwable $error, $lambdaInitializatio 'errorType' => 'Internal', 'stackTrace' => [], ]; - echo "$error\n"; + echo "Fatal error: $error\n"; } echo "The function failed to start. AWS Lambda will restart the process, do not be surprised if you see the error message twice.\n"; From 05bc84d6389249356aeb89fabcf103848cf017bc Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 14:40:01 +0200 Subject: [PATCH 6/7] Fix CS --- src/Runtime/LambdaRuntime.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Runtime/LambdaRuntime.php b/src/Runtime/LambdaRuntime.php index 96b3a7996..0b4014c4c 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -237,10 +237,9 @@ private function signalFailure(string $invocationId, Throwable $error): void /** * Abort the lambda and signal to the runtime API that we failed to initialize this instance. * - * @param 'Runtime.NoSuchHandler'|'Runtime.UnknownReason' $lambdaInitializationReason - * * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-initerror * + * @phpstan-param 'Runtime.NoSuchHandler'|'Runtime.UnknownReason' $lambdaInitializationReason * @phpstan-return never-returns */ public function failInitialization( @@ -287,9 +286,8 @@ public function failInitialization( /** * @param string[] $headers - * - * @throws ResponseTooBig * @throws Exception + * @throws ResponseTooBig */ private function postJson(string $url, mixed $data, array $headers = []): void { @@ -313,7 +311,7 @@ private function postJson(string $url, mixed $data, array $headers = []): void curl_setopt($this->curlHandleResult, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($jsonData), - ...$headers + ...$headers, ]); $body = curl_exec($this->curlHandleResult); From 38d2e3aea1e25a41568c8916911b317261ce5807 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 14 Aug 2023 15:15:50 +0200 Subject: [PATCH 7/7] Add tests for the JS serverless plugin --- composer.json | 3 +- tests/Plugin/serverless-runtime-root.yml | 14 +++++ tests/Plugin/serverless.yml | 30 ++++++++++ tests/PluginTest.php | 70 ++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/Plugin/serverless-runtime-root.yml create mode 100644 tests/Plugin/serverless.yml create mode 100644 tests/PluginTest.php diff --git a/composer.json b/composer.json index e50515bc4..7bfda7ba2 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "guzzlehttp/guzzle": "^7.5", "phpstan/phpstan": "^1.10.26", "phpunit/phpunit": "^9.6.10", - "symfony/console": "^4.4|^5.0|^6.0|^7.0" + "symfony/console": "^4.4|^5.0|^6.0|^7.0", + "symfony/yaml": "^6.3" }, "scripts": { "test": [ diff --git a/tests/Plugin/serverless-runtime-root.yml b/tests/Plugin/serverless-runtime-root.yml new file mode 100644 index 000000000..206332e32 --- /dev/null +++ b/tests/Plugin/serverless-runtime-root.yml @@ -0,0 +1,14 @@ +service: bref +provider: + name: aws + runtime: php-83 + +plugins: + - ../../index.js + +functions: + function: + handler: function.php + function-arm: + handler: function.php + architecture: arm64 diff --git a/tests/Plugin/serverless.yml b/tests/Plugin/serverless.yml new file mode 100644 index 000000000..867f2253a --- /dev/null +++ b/tests/Plugin/serverless.yml @@ -0,0 +1,30 @@ +service: bref +provider: + name: aws + +plugins: + - ../../index.js + +functions: + function: + handler: function.php + runtime: php-83 + fpm: + handler: fpm.php + runtime: php-83-fpm + console: + handler: console.php + runtime: php-83-console + + function-arm: + handler: function.php + architecture: arm64 + runtime: php-83 + fpm-arm: + handler: fpm.php + architecture: arm64 + runtime: php-83-fpm + console-arm: + handler: console.php + architecture: arm64 + runtime: php-83-console diff --git a/tests/PluginTest.php b/tests/PluginTest.php new file mode 100644 index 000000000..4629a413e --- /dev/null +++ b/tests/PluginTest.php @@ -0,0 +1,70 @@ +slsPrint('serverless.yml'); + + self::assertFunction($output['functions']['function'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', + ]); + self::assertFunction($output['functions']['fpm'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:php-83-fpm:', + ]); + self::assertFunction($output['functions']['console'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', + 'arn:aws:lambda:us-east-1:534081306603:layer:console:', + ]); + + self::assertFunction($output['functions']['function-arm'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', + ]); + self::assertFunction($output['functions']['fpm-arm'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83-fpm:', + ]); + self::assertFunction($output['functions']['console-arm'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', + 'arn:aws:lambda:us-east-1:534081306603:layer:console:', + ]); + } + + public function test the plugin adds the layers when the runtime is set in the provider(): void + { + $output = $this->slsPrint('serverless-runtime-root.yml'); + + self::assertFunction($output['functions']['function'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', + ]); + self::assertFunction($output['functions']['function-arm'], 'provided.al2', [ + 'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', + ]); + } + + private function slsPrint(string $configFile): array + { + $process = (new Process( + ['serverless', 'print', '-c', $configFile], + cwd: __DIR__ . '/Plugin', + env: [ + 'SLS_TELEMETRY_DISABLED' => '1', // else we sometimes get HTTP errors (and its faster) + ], + ))->mustRun(); + return Yaml::parse($process->getOutput()); + } + + private static function assertFunction(array $config, string $runtime, array $layers): void + { + self::assertEquals($runtime, $config['runtime']); + self::assertCount(count($layers), $config['layers']); + foreach ($layers as $index => $layer) { + self::assertStringStartsWith($layer, $config['layers'][$index]); + } + } +}