Skip to content

Commit d6e40f5

Browse files
committed
reorder and add additional logging data to custom runtime demo
1 parent 222bcae commit d6e40f5

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

custom-runtime-extension-demo/extensionssrc/extensions/extension1.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ forward_sigterm_and_wait() {
2525

2626
# Registration
2727
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"
3029
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
3130

3231
RESPONSE=$(<$TMPFILE)
3332
HEADINFO=$(<$HEADERS)
34-
echo "[${LAMBDA_EXTENSION_NAME}] Register response: ${RESPONSE}"
35-
sleep 1
3633
# Extract Extension ID from response headers
3734
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+
3837

3938
# Event processing
4039
while true
4140
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"
4342

4443
# Get an event. The HTTP request will block until one is received
4544
curl -sS -L -XGET "http://${AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension/event/next" --header "Lambda-Extension-Identifier: ${EXTENSION_ID}" > $TMPFILE &

custom-runtime-extension-demo/extensionssrc/extensions/extension2.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ forward_sigterm_and_wait() {
2525

2626
# Registration
2727
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"
3029
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
3130

3231
RESPONSE=$(<$TMPFILE)
3332
HEADINFO=$(<$HEADERS)
34-
echo "[${LAMBDA_EXTENSION_NAME}] Register response: ${RESPONSE}"
35-
sleep 1
3633
# Extract Extension ID from response headers
3734
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+
3837

3938
# Event processing
4039
while true
4140
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"
4342

4443
# Get an event. The HTTP request will block until one is received
4544
curl -sS -L -XGET "http://${AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension/event/next" --header "Lambda-Extension-Identifier: ${EXTENSION_ID}" > $TMPFILE &
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: MIT-0
33

4+
echo "[function] Running init code outside handler"
5+
46
function handler () {
57
EVENT_DATA=$1
6-
echo "[function] Receiving invocation: '$EVENT_DATA'"
8+
echo "[function] handler receiving invocation: '$EVENT_DATA'"
9+
sleep 1
710
RESPONSE="Echoing request: '$EVENT_DATA'"
811
echo $RESPONSE
912
}

custom-runtime-extension-demo/runtime/bootstrap

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ forward_sigterm_and_wait() {
2222
trap - SIGTERM
2323
}
2424

25-
# Initialization - load function handler
26-
source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
27-
2825
echo "[runtime] Initializing..."
2926

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+
3031
# Processing
3132
while true
3233
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"
3435

3536
HEADERS="$(mktemp)"
3637

@@ -46,12 +47,12 @@ do
4647
# Extract request ID by scraping response headers received above
4748
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
4849

49-
echo "[runtime] Executing function: $_HANDLER"
50+
echo "[runtime] Executing function handler: $_HANDLER"
5051

5152
# 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"
5556

5657
# Send the response
5758
curl -sS -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE" > $TMPFILE

0 commit comments

Comments
 (0)