-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.php
40 lines (32 loc) · 978 Bytes
/
handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php declare(strict_types=1);
use My\App\MyClass;
require __DIR__ . '/vendor/autoload.php';
$awsLambdaRuntimeApi = $argv[1];
$requestId = $argv[2];
try {
$data = json_decode($argv[3], true);
$response = MyClass::run($data);
// Return a successful response to the Lambda runtime
exec(<<<CMD
curl -X POST \
"http://${awsLambdaRuntimeApi}/2018-06-01/runtime/invocation/${requestId}/response" \
-d "${response}"
CMD
);
}
// Catch any errors and return an error response to the Lambda runtime
catch (\Throwable $t) {
$response = json_encode(
[
"errorMessage" => $t->getMessage(),
"errorType" => $t->getCode(),
]
);
exec(<<<CMD
curl -X POST \
"http://${awsLambdaRuntimeApi}/2018-06-01/runtime/invocation/${requestId}/error" \
-d "${response}" \
--header "Lambda-Runtime-Function-Error-Type: Unhandled"
CMD
);
}