File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
- #! /bin/sh
1
+ #! /bin/bash
2
2
3
3
# https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html
4
4
# https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html
33
33
HANDLER_FILE=" $( echo $_HANDLER | cut -d. -f1) .sh"
34
34
HANDLER_FUNC=" $( echo $_HANDLER | cut -d. -f2) "
35
35
36
+ echo " HANDLER_FILE: $HANDLER_FILE " >&2
37
+ echo " HANDLER_FUNC: $HANDLER_FUNC " >&2
38
+ echo " LAMBDA_TASK_ROOT: $LAMBDA_TASK_ROOT " >&2
39
+ echo " AWS_LAMBDA_RUNTIME_API: $AWS_LAMBDA_RUNTIME_API " >&2
40
+ echo " Sourcing $LAMBDA_TASK_ROOT /$HANDLER_FILE " >&2
41
+
42
+
36
43
if [ ! -f " $LAMBDA_TASK_ROOT /$HANDLER_FILE " ]; then
37
44
send_init_error " Handler file not found: $HANDLER_FILE "
38
45
fi
55
62
REQUEST_ID=$( grep -Fi Lambda-Runtime-Aws-Request-Id " $HEADERS " | tr -d ' [:space:]' | cut -d: -f2)
56
63
57
64
# Run the handler function from the script with error handling
58
- if RESPONSE=$( " $HANDLER_FUNC " " $EVENT_DATA " 2>&1 ) ; then
65
+ # Let stderr go to CloudWatch logs, only capture stdout as response
66
+ if RESPONSE=$( " $HANDLER_FUNC " " $EVENT_DATA " ) ; then
59
67
# Success - send response
60
68
echo " $RESPONSE " | curl -sS -X POST \
61
69
" http://${AWS_LAMBDA_RUNTIME_API} /2018-06-01/runtime/invocation/${REQUEST_ID} /response" \
62
70
-H " Content-Type: application/json" \
63
71
-d @-
64
72
else
65
73
# Error - send error response
66
- send_invocation_error " $REQUEST_ID " " Handler function failed: $RESPONSE "
74
+ send_invocation_error " $REQUEST_ID " " Handler function failed with exit code $? "
67
75
fi
68
76
69
77
rm -f " $HEADERS "
You can’t perform that action at this time.
0 commit comments