Skip to content

Commit 9dab38a

Browse files
author
Graham Krizek
committed
Working runtime!!
1 parent 6553082 commit 9dab38a

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
test*
12
.DS_Store
23
.vscode

bootstrap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
#set -u
3+
set -uo pipefail
44

55
# Constants
66
RUNTIME_PATH="2018-06-01/runtime"
@@ -20,7 +20,7 @@ sendRuntimeError () {
2020
ERROR_TYPE=$3
2121
STACK_TRACE=$4
2222
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\", \"stackTrace\": \"$STACK_TRACE\"}"
23-
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/error" > /dev/null
23+
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/error" > /dev/null
2424
}
2525

2626
# Send successful response to Lambda API
@@ -42,17 +42,17 @@ source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
4242
while true
4343
do
4444
HEADERS="$(mktemp)"
45+
RESPONSE="$(mktemp)"
4546
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/next")
4647
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
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
48+
$(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA" >&1 2> $RESPONSE | cat
5049
EXIT_CODE=$?
5150
if [[ $EXIT_CODE -eq "0" ]]; then
52-
sendResponse $REQUEST_ID $LAMBDA_RETURN_VALUE
51+
sendResponse "$REQUEST_ID" "$(cat $RESPONSE)"
5352
else
54-
echo "failure"
55-
echo $RESPONSE
56-
sendRuntimeError $REQUEST_ID "Exited with code $EXIT_CODE" "RuntimeErrorException" "$RESPONSE"
53+
cat $RESPONSE
54+
sendRuntimeError "$REQUEST_ID" "Exited with code $EXIT_CODE" "RuntimeErrorException" "$(cat $RESPONSE)"
5755
fi
56+
rm -f $HEADERS
57+
rm -f $RESPONSE
5858
done

index.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
function handler () {
4+
set -e
5+
EVENT_DATA=$1
6+
echo "this is my function"
7+
echo "this is my function"
8+
for i in `seq 1 25`;
9+
do
10+
echo $i
11+
done
12+
lsssss
13+
echo $?
14+
echo "after....."
15+
echo "TESTING" > /tmp/testing.out
16+
echo $?
17+
echo $EVENT_DATA >&2
18+
19+
}

test.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)