Skip to content

Instantly share code, notes, and snippets.

@parallaxisjones
Last active November 22, 2024 17:44
Show Gist options
  • Save parallaxisjones/ada2992b0b32760bf6472575ac668ec7 to your computer and use it in GitHub Desktop.
Save parallaxisjones/ada2992b0b32760bf6472575ac668ec7 to your computer and use it in GitHub Desktop.
Export lambda function and cloudwatch log link to bookmark file
#!/bin/bash
# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq is not installed. Please install jq to use this script."
exit 1
fi
# Check if a search term is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <search-term>"
exit 1
fi
SEARCH_TERM="$1"
# Generate a timestamp for the filename
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
OUTPUT_FILE="lambda_bookmarks_${TIMESTAMP}.html"
# Start Netscape Bookmark File
echo "<!DOCTYPE NETSCAPE-Bookmark-file-1>" > "$OUTPUT_FILE"
echo "<!-- This is an automatically generated file. -->" >> "$OUTPUT_FILE"
echo "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">" >> "$OUTPUT_FILE"
echo "<TITLE>Bookmarks</TITLE>" >> "$OUTPUT_FILE"
echo "<H1>Bookmarks</H1>" >> "$OUTPUT_FILE"
echo "<DL><p>" >> "$OUTPUT_FILE"
# Get all Lambda functions and filter by the provided search term
echo "Fetching Lambda functions..."
aws lambda list-functions --query "Functions[?contains(FunctionName, \`${SEARCH_TERM}\`)]" --output json | jq -c '.[]' | while read -r function; do
FUNCTION_NAME=$(echo "$function" | jq -r '.FunctionName')
REGION=$(aws configure get region)
# Generate CloudWatch Logs link
LOG_GROUP="/aws/lambda/$FUNCTION_NAME"
CLOUDWATCH_LOGS_URL="https://${REGION}.console.aws.amazon.com/cloudwatch/home?region=${REGION}#logsV2:log-groups/log-group/${LOG_GROUP//\//%2F}"
# Generate Lambda function link
LAMBDA_FUNCTION_URL="https://${REGION}.console.aws.amazon.com/lambda/home?region=${REGION}#/functions/${FUNCTION_NAME}?tab=code"
# Append Lambda function and CloudWatch links to the bookmark file
echo " <DT><H3>${FUNCTION_NAME}</H3>" >> "$OUTPUT_FILE"
echo " <DL><p>" >> "$OUTPUT_FILE"
echo " <DT><A HREF=\"${CLOUDWATCH_LOGS_URL}\" ADD_DATE=\"$(date +%s)\">CloudWatch Logs</A>" >> "$OUTPUT_FILE"
echo " <DT><A HREF=\"${LAMBDA_FUNCTION_URL}\" ADD_DATE=\"$(date +%s)\">Lambda Function</A>" >> "$OUTPUT_FILE"
echo " </DL><p>" >> "$OUTPUT_FILE"
done
# Close Netscape Bookmark File
echo "</DL><p>" >> "$OUTPUT_FILE"
echo "Bookmarks saved to $OUTPUT_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment