-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow extensions to be disabled
- Loading branch information
Sudhakar Reddy
committed
Oct 5, 2024
1 parent
71388dd
commit 41ea0b1
Showing
6 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# Name of the extension | ||
EXTENSION_NAME="bash-extension" | ||
|
||
# Log file path | ||
LOG_FILE="/tmp/extension.log" | ||
|
||
|
||
# Function to register the extension with the Lambda service | ||
register_extension() { | ||
curl -s -D /tmp/headers -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension/register" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Lambda-Extension-Name: $EXTENSION_NAME" \ | ||
-d '{"events": ["INVOKE"]}' | ||
EXTENSION_ID=$(cat /tmp/headers | grep "Lambda-Extension-Identifier" | grep -oP '[a-f0-9\-]{36}') | ||
echo "Extension Id: $EXTENSION_ID" >> $LOG_FILE | ||
} | ||
|
||
# Function to process events | ||
process_events() { | ||
# Main loop | ||
while true; do | ||
echo "Waiting for next event" | ||
EVENT_DATA=$(curl -s -X GET \ | ||
-H "Lambda-Extension-Identifier: $EXTENSION_ID" \ | ||
"http://${AWS_LAMBDA_RUNTIME_API}/2020-01-01/extension/event/next") | ||
|
||
# Check if the event is an invocation | ||
if [[ $(echo "$EVENT_DATA" | jq -r '.eventType') == "INVOKE" ]]; then | ||
echo "Invocation event received: $EVENT_DATA" | ||
# Log the invocation event data | ||
echo "$EVENT_DATA" >> "$LOG_FILE" | ||
fi | ||
done | ||
} | ||
|
||
# Register the extension | ||
register_extension | ||
|
||
# Process events | ||
process_events |
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