Created
August 4, 2020 21:38
-
-
Save acomagu/66e8d66a5c7403be629afc1e90e6a33c to your computer and use it in GitHub Desktop.
The shellscript bootstrap for AWS Lambda Custom Runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -euo pipefail | |
| function report_init_error() { | |
| curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/init/error" -d@- --header "Lambda-Runtime-Function-Error-Type: Unhandled" | |
| } | |
| function report_invocation_error() { | |
| curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/error" -d@- --header "Lambda-Runtime-Function-Error-Type: Unhandled" | |
| } | |
| source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f0).sh" || { report_init_error <<<'{"errorMessage":"Failed to source the handler file."}'; false; } | |
| while true | |
| do | |
| headers="$(mktemp)" | |
| event=$(curl -sS -LD "$headers" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next") | |
| request_id=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$headers" | tr -d '[:space:]' | cut -d: -f2) | |
| response=$($(echo "$_HANDLER" | cut -d. -f2) "$event") || { report_invocation_error <<<'{"errorMessage":"Invocation Error"}'; continue; } | |
| curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$request_id/response" -d "$response" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment