File tree Expand file tree Collapse file tree 4 files changed +21
-19
lines changed
custom-runtime-extension-demo Expand file tree Collapse file tree 4 files changed +21
-19
lines changed Original file line number Diff line number Diff line change @@ -25,21 +25,20 @@ forward_sigterm_and_wait() {
25
25
26
26
# Registration
27
27
HEADERS=" $( mktemp) "
28
- echo " [${LAMBDA_EXTENSION_NAME} ] Registering..."
29
- sleep 1
28
+ echo " [${LAMBDA_EXTENSION_NAME} ] Registering at http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/register"
30
29
curl -sS -LD " $HEADERS " -XPOST " http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/register" --header " Lambda-Extension-Name: ${LAMBDA_EXTENSION_NAME} " -d " { \" events\" : [\" INVOKE\" , \" SHUTDOWN\" ]}" > $TMPFILE
31
30
32
31
RESPONSE=$( < $TMPFILE )
33
32
HEADINFO=$( < $HEADERS )
34
- echo " [${LAMBDA_EXTENSION_NAME} ] Register response: ${RESPONSE} "
35
- sleep 1
36
33
# Extract Extension ID from response headers
37
34
EXTENSION_ID=$( grep -Fi Lambda-Extension-Identifier " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2)
35
+ echo " [${LAMBDA_EXTENSION_NAME} ] Registration response: ${RESPONSE} with EXTENSION_ID $( grep -Fi Lambda-Extension-Identifier " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2) "
36
+
38
37
39
38
# Event processing
40
39
while true
41
40
do
42
- echo " [${LAMBDA_EXTENSION_NAME} ] Waiting for event... "
41
+ echo " [${LAMBDA_EXTENSION_NAME} ] Waiting for event. Get /next event from http:// ${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/event/next "
43
42
44
43
# Get an event. The HTTP request will block until one is received
45
44
curl -sS -L -XGET " http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/event/next" --header " Lambda-Extension-Identifier: ${EXTENSION_ID} " > $TMPFILE &
Original file line number Diff line number Diff line change @@ -25,21 +25,20 @@ forward_sigterm_and_wait() {
25
25
26
26
# Registration
27
27
HEADERS=" $( mktemp) "
28
- echo " [${LAMBDA_EXTENSION_NAME} ] Registering..."
29
- sleep 1
28
+ echo " [${LAMBDA_EXTENSION_NAME} ] Registering at http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/register"
30
29
curl -sS -LD " $HEADERS " -XPOST " http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/register" --header " Lambda-Extension-Name: ${LAMBDA_EXTENSION_NAME} " -d " { \" events\" : [\" INVOKE\" , \" SHUTDOWN\" ]}" > $TMPFILE
31
30
32
31
RESPONSE=$( < $TMPFILE )
33
32
HEADINFO=$( < $HEADERS )
34
- echo " [${LAMBDA_EXTENSION_NAME} ] Register response: ${RESPONSE} "
35
- sleep 1
36
33
# Extract Extension ID from response headers
37
34
EXTENSION_ID=$( grep -Fi Lambda-Extension-Identifier " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2)
35
+ echo " [${LAMBDA_EXTENSION_NAME} ] Registration response: ${RESPONSE} with EXTENSION_ID $( grep -Fi Lambda-Extension-Identifier " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2) "
36
+
38
37
39
38
# Event processing
40
39
while true
41
40
do
42
- echo " [${LAMBDA_EXTENSION_NAME} ] Waiting for event... "
41
+ echo " [${LAMBDA_EXTENSION_NAME} ] Waiting for event. Get /next event from http:// ${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/event/next "
43
42
44
43
# Get an event. The HTTP request will block until one is received
45
44
curl -sS -L -XGET " http://${AWS_LAMBDA_RUNTIME_API} /2020-01-01/extension/event/next" --header " Lambda-Extension-Identifier: ${EXTENSION_ID} " > $TMPFILE &
Original file line number Diff line number Diff line change 1
1
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: MIT-0
3
3
4
+ echo " [function] Running init code outside handler"
5
+
4
6
function handler () {
5
7
EVENT_DATA=$1
6
- echo " [function] Receiving invocation: '$EVENT_DATA '"
8
+ echo " [function] handler receiving invocation: '$EVENT_DATA '"
9
+ sleep 1
7
10
RESPONSE=" Echoing request: '$EVENT_DATA '"
8
11
echo $RESPONSE
9
12
}
Original file line number Diff line number Diff line change @@ -22,15 +22,16 @@ forward_sigterm_and_wait() {
22
22
trap - SIGTERM
23
23
}
24
24
25
- # Initialization - load function handler
26
- source $LAMBDA_TASK_ROOT /" $( echo $_HANDLER | cut -d. -f1) .sh"
27
-
28
25
echo " [runtime] Initializing..."
29
26
27
+ # Initialization - load function
28
+ echo " [runtime] Load function from $LAMBDA_TASK_ROOT /$( echo $_HANDLER | cut -d. -f1) .sh"
29
+ source $LAMBDA_TASK_ROOT /" $( echo $_HANDLER | cut -d. -f1) .sh"
30
+
30
31
# Processing
31
32
while true
32
33
do
33
- echo " [runtime] Waiting for invocation... "
34
+ echo " [runtime] Waiting for invocation, Get /next event from http:// ${AWS_LAMBDA_RUNTIME_API} /2018-06-01/runtime/invocation/next "
34
35
35
36
HEADERS=" $( mktemp) "
36
37
46
47
# Extract request ID by scraping response headers received above
47
48
REQUEST_ID=$( grep -Fi Lambda-Runtime-Aws-Request-Id " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2)
48
49
49
- echo " [runtime] Executing function: $_HANDLER "
50
+ echo " [runtime] Executing function handler : $_HANDLER "
50
51
51
52
# Execute the handler function from the script
52
- RESPONSE=$( $( echo " $_HANDLER " | cut -d. -f2) " $EVENT_DATA " )
53
-
54
- echo " [runtime] Sending invocation response: $RESPONSE "
53
+ RESPONSE=$( $( echo " $_HANDLER " | cut -d. -f2) " $EVENT_DATA " )
54
+ sleep 1
55
+ echo " [runtime] Sending invocation response: $RESPONSE to http:// ${AWS_LAMBDA_RUNTIME_API} /2018-06-01/runtime/invocation/ $REQUEST_ID /response "
55
56
56
57
# Send the response
57
58
curl -sS -X POST " http://${AWS_LAMBDA_RUNTIME_API} /2018-06-01/runtime/invocation/$REQUEST_ID /response" -d " $RESPONSE " > $TMPFILE
You can’t perform that action at this time.
0 commit comments