This repository was archived by the owner on Dec 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,11 @@ RUN mkdir bin && \
39
39
RUN curl -sS https://getcomposer.org/installer | ./bin/php -- --install-dir=/runtime/bin --filename=composer && \
40
40
./bin/php ./bin/composer require guzzlehttp/guzzle
41
41
42
+ # Copy in runtime bootstrap
43
+ COPY runtime/bootstrap /runtime/
44
+
42
45
# ##### Create runtime image ######
43
46
44
47
FROM lambci/lambda:provided as runtime
45
48
46
- COPY --from=builder /runtime /opt
49
+ COPY --from=builder /runtime/ /opt/
Original file line number Diff line number Diff line change
1
+ #!/opt/bin/php
2
+ <?php
3
+
4
+ // This invokes Composer's autoloader so that we'll be able to use Guzzle and any other 3rd party libraries we need.
5
+ require __DIR__ . '/vendor/autoload.php ' ;
6
+
7
+ function getNextRequest ()
8
+ {
9
+ $ client = new \GuzzleHttp \Client ();
10
+ $ response = $ client ->get ('http:// ' . $ _ENV ['AWS_LAMBDA_RUNTIME_API ' ] . '/2018-06-01/runtime/invocation/next ' );
11
+
12
+ return [
13
+ 'invocationId ' => $ response ->getHeader ('Lambda-Runtime-Aws-Request-Id ' )[0 ],
14
+ 'payload ' => json_decode ((string ) $ response ->getBody (), true )
15
+ ];
16
+ }
17
+
18
+ function sendResponse ($ invocationId , $ response )
19
+ {
20
+ $ client = new \GuzzleHttp \Client ();
21
+ $ client ->post (
22
+ 'http:// ' . $ _ENV ['AWS_LAMBDA_RUNTIME_API ' ] . '/2018-06-01/runtime/invocation/ ' . $ invocationId . '/response ' ,
23
+ ['body ' => $ response ]
24
+ );
25
+ }
26
+
27
+ // This is the request processing loop. Barring unrecoverable failure, this loop runs until the environment shuts down.
28
+ do {
29
+ // Ask the runtime API for a request to handle.
30
+ $ request = getNextRequest ();
31
+
32
+ // Obtain the function name from the _HANDLER environment variable and ensure the function's code is available.
33
+ $ handlerFunction = array_slice (explode ('. ' , $ _ENV ['_HANDLER ' ]), -1 )[0 ];
34
+ require_once $ _ENV ['LAMBDA_TASK_ROOT ' ] . '/src/ ' . $ handlerFunction . '.php ' ;
35
+
36
+ // Execute the desired function and obtain the response.
37
+ $ response = $ handlerFunction ($ request ['payload ' ]);
38
+
39
+ // Submit the response back to the runtime API.
40
+ sendResponse ($ request ['invocationId ' ], $ response );
41
+ } while (true );
You can’t perform that action at this time.
0 commit comments