Skip to content

Commit 6553082

Browse files
author
Graham Krizek
committed
progress with runtime
1 parent fdd7769 commit 6553082

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

bootstrap

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
#!/bin/sh
22

3-
set -u
3+
#set -u
44

5+
# Constants
56
RUNTIME_PATH="2018-06-01/runtime"
67

7-
# Response
8+
# Send initialization error to Lambda API
89
sendInitError () {
910
ERROR_MESSAGE=$1
1011
ERROR_TYPE=$2
1112
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\"}"
12-
echo $ERROR >&2
1313
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/init/error" > /dev/null
1414
}
1515

16+
# Send runtime error to Lambda API
1617
sendRuntimeError () {
17-
ERROR_MESSAGE=$1
18-
ERROR_TYPE=$2
19-
REQUEST_ID=$3
20-
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\"}"
21-
echo $ERROR >&2
18+
REQUEST_ID=$1
19+
ERROR_MESSAGE=$2
20+
ERROR_TYPE=$3
21+
STACK_TRACE=$4
22+
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\", \"stackTrace\": \"$STACK_TRACE\"}"
2223
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/error" > /dev/null
2324
}
2425

26+
# Send successful response to Lambda API
2527
sendResponse () {
26-
RESPONSE=$1
28+
REQUEST_ID=$1
29+
RESPONSE=$2
2730
curl -sS -X POST -d "$RESPONSE" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/response" > /dev/null
2831
}
2932

@@ -41,17 +44,15 @@ do
4144
HEADERS="$(mktemp)"
4245
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/next")
4346
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
44-
RESPONSE=$($(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA")
45-
#echo $EXIT_CODE >&2
46-
git ls
47-
echo $?
48-
echo $? >&2
49-
#echo $RESPONSE >&2
50-
if [[ $? -eq 0 ]]; then
51-
echo "GOOD RESPONSE" >&2
52-
sendResponse $RESPONSE
47+
RESPONSE=$($(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA" 2>&1 >/dev/null)
48+
# Goal here is to only capture STDERR to the $RESPONSE variable and allow STDOUT to be logged like normal.
49+
# Then for successful response messages we set them to a global variable $LAMBDA_RETURN_VALUE
50+
EXIT_CODE=$?
51+
if [[ $EXIT_CODE -eq "0" ]]; then
52+
sendResponse $REQUEST_ID $LAMBDA_RETURN_VALUE
5353
else
54-
echo "BAD RESPONSE" >&2
55-
sendRuntimeError "ErrorMessage" "ErrorType" $REQUEST_ID
54+
echo "failure"
55+
echo $RESPONSE
56+
sendRuntimeError $REQUEST_ID "Exited with code $EXIT_CODE" "RuntimeErrorException" "$RESPONSE"
5657
fi
5758
done

test.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/bash
22

33
function handler () {
4+
set -e
45
EVENT_DATA=$1
5-
unset command_not_found_handle
6-
echo "this is my function" >&2
7-
git ls
6+
echo "this is my function"
7+
lsssss
8+
RETURN_VALUE="this is the return value"
89
echo $?
910
echo $EVENT_DATA
1011
}

0 commit comments

Comments
 (0)