11<?php namespace xp \lambda ;
22
33use Throwable ;
4- use com \amazon \aws \lambda \{Context , Environment };
4+ use com \amazon \aws \lambda \{Context , Environment , Handler };
55use io \IOException ;
6- use lang \{XPClass , XPException , Environment as System };
6+ use lang \{XPClass , XPException , IllegalArgumentException , Environment as System };
77use peer \http \{HttpConnection , RequestData };
88use text \json \{Json , StreamInput };
99use util \cmd \Console ;
1212 * Custom AWS Lambda runtimes
1313 *
1414 * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
15+ * @test com.amazon.aws.lambda.unittest.AwsRunnerTest
1516 */
1617class AwsRunner {
1718
@@ -22,9 +23,16 @@ class AwsRunner {
2223 * @param [:string] $environment
2324 * @param io.streams.StringWriter $writer
2425 * @return com.amazon.aws.lambda.Handler
26+ * @throws lang.ClassLoadingException
27+ * @throws lang.IllegalArgumentException
2528 */
26- private static function handler ($ environment , $ writer ) {
27- return XPClass::forName ($ environment ['_HANDLER ' ])->newInstance (new Environment (
29+ public static function handler ($ environment , $ writer ) {
30+ $ impl = XPClass::forName ($ environment ['_HANDLER ' ] ?? '' );
31+ if (!$ impl ->isSubclassOf (Handler::class)) {
32+ throw new IllegalArgumentException ('Class ' .$ impl ->getName ().' is not a lambda handler ' );
33+ }
34+
35+ return $ impl ->newInstance (new Environment (
2836 $ environment ['LAMBDA_TASK_ROOT ' ] ?? '. ' ,
2937 $ writer ,
3038 $ environment
@@ -40,7 +48,7 @@ private static function handler($environment, $writer) {
4048 * @param string $path
4149 * @return peer.http.HttpConnection
4250 */
43- private static function endpoint ($ environment , $ path ) {
51+ public static function endpoint ($ environment , $ path ) {
4452 $ c = new HttpConnection ("http:// {$ environment ['AWS_LAMBDA_RUNTIME_API ' ]}/2018-06-01/runtime/ {$ path }" );
4553
4654 // Use a 15 minute timeout, this is the maximum lambda runtime, see
0 commit comments