Skip to content

Commit fdd7769

Browse files
author
Graham Krizek
committed
Playing around with exit codes
1 parent 61eac56 commit fdd7769

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

bootstrap

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

3-
set -euo pipefail
3+
set -u
44

55
RUNTIME_PATH="2018-06-01/runtime"
66

@@ -11,7 +11,6 @@ sendInitError () {
1111
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\"}"
1212
echo $ERROR >&2
1313
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/init/error" > /dev/null
14-
exit 1
1514
}
1615

1716
sendRuntimeError () {
@@ -20,20 +19,18 @@ sendRuntimeError () {
2019
REQUEST_ID=$3
2120
ERROR="{\"errorMessage\": \"$ERROR_MESSAGE\", \"errorType\": \"$ERROR_TYPE\"}"
2221
echo $ERROR >&2
23-
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/error"
22+
curl -sS -X POST -d "$ERROR" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/error" > /dev/null
2423
}
2524

2625
sendResponse () {
2726
RESPONSE=$1
2827
curl -sS -X POST -d "$RESPONSE" "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/${REQUEST_ID}/response" > /dev/null
2928
}
3029

31-
# Make sure file exists and it can be sourced
32-
{
33-
[[ ! -f $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh" ]] && . $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
34-
} || {
30+
# Make sure handler file exists
31+
if [[ ! -f $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh" ]]; then
3532
sendInitError "Failed to load handler '$(echo $_HANDLER | cut -d. -f2)' from module '$(echo $_HANDLER | cut -d. -f1)'" "InvalidHandlerException"
36-
}
33+
fi
3734

3835
# Initialization
3936
source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
@@ -42,13 +39,14 @@ source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh"
4239
while true
4340
do
4441
HEADERS="$(mktemp)"
45-
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocaion/next")
46-
if [[ $? != 0 ]]; then
47-
echo "INIT ERROR" >&2
48-
sendInitError "There was a problem retriving invocations" "InternalRuntimeException"
49-
fi
42+
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/${RUNTIME_PATH}/invocation/next")
5043
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
5144
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
5250
if [[ $? -eq 0 ]]; then
5351
echo "GOOD RESPONSE" >&2
5452
sendResponse $RESPONSE

test.sh

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

33
function handler () {
44
EVENT_DATA=$1
5-
5+
unset command_not_found_handle
66
echo "this is my function" >&2
77
git ls
8+
echo $?
89
echo $EVENT_DATA
910
}

0 commit comments

Comments
 (0)