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/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 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 c4843eda4..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()); + $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..0b4014c4c 100755 --- a/src/Runtime/LambdaRuntime.php +++ b/src/Runtime/LambdaRuntime.php @@ -239,42 +239,57 @@ private function signalFailure(string $invocationId, Throwable $error): void * * @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(string $message, ?Throwable $error = null): void - { + public function failInitialization( + string|Throwable $error, + string $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) { + $traceAsArray = explode(PHP_EOL, $error->getTraceAsString()); + $data = [ + 'errorMessage' => $error->getMessage(), + 'errorType' => get_class($error), + 'stackTrace' => $traceAsArray, + ]; printf( - "Fatal error: %s in %s:%d\nStack trace:\n%s", - $errorMessage, + "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 = [ + 'errorMessage' => $error, + 'errorType' => 'Internal', + 'stackTrace' => [], + ]; + 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"; + $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); } /** - * @throws ResponseTooBig + * @param string[] $headers * @throws Exception + * @throws ResponseTooBig */ - 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 +311,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); 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]); + } + } +}