Skip to content

Commit 4a4885e

Browse files
committed
feat: make sure stderr get logged
* refactor: better output handling in bootstrap
1 parent d8a649e commit 4a4885e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

runtime/bootstrap

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

33
# https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html
44
# https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html
@@ -33,6 +33,13 @@ fi
3333
HANDLER_FILE="$(echo $_HANDLER | cut -d. -f1).sh"
3434
HANDLER_FUNC="$(echo $_HANDLER | cut -d. -f2)"
3535

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+
3643
if [ ! -f "$LAMBDA_TASK_ROOT/$HANDLER_FILE" ]; then
3744
send_init_error "Handler file not found: $HANDLER_FILE"
3845
fi
@@ -55,15 +62,16 @@ do
5562
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
5663

5764
# 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
5967
# Success - send response
6068
echo "$RESPONSE" | curl -sS -X POST \
6169
"http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${REQUEST_ID}/response" \
6270
-H "Content-Type: application/json" \
6371
-d @-
6472
else
6573
# 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 $?"
6775
fi
6876

6977
rm -f "$HEADERS"

0 commit comments

Comments
 (0)