Created
December 17, 2023 07:27
-
-
Save ayush--s/fb0b99294e4c2578923e76884c2d24c1 to your computer and use it in GitHub Desktop.
docker custom runtime
This file contains 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 | |
# Initialization - load function handler | |
source $LAMBDA_TASK_ROOT/"$(echo $_HANDLER | cut -d. -f1).sh" | |
# Processing | |
while true | |
do | |
HEADERS="$(mktemp)" | |
# Get an event. The HTTP request will block until one is received | |
EVENT_DATA=$(curl -sS -LD "$HEADERS" "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next") | |
# Extract request ID by scraping response headers received above | |
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2) | |
# Run the handler function from the script | |
RESPONSE=$($(echo "$_HANDLER" | cut -d. -f2) "$EVENT_DATA") | |
# Send the response | |
curl --silent "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE" | |
done |
This file contains 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
FROM public.ecr.aws/lambda/provided:latest | |
COPY bootstrap ${LAMBDA_RUNTIME_DIR} | |
COPY function.sh ${LAMBDA_TASK_ROOT} | |
RUN chmod a+x ${LAMBDA_RUNTIME_DIR}/bootstrap | |
CMD [ "function.handler" ] |
This file contains 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
function handler () { | |
EVENT_DATA=$1 | |
echo "$EVENT_DATA" 1>&2; | |
RESPONSE="Echoing request: '$EVENT_DATA'" | |
echo $RESPONSE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment