- Download all AWS Lambda functions as ZIP files.
- Search for a keyword in the ZIP files.
I used it to check for Lambda containing specific keywords in a chaotic verification account that includes many direct-written Lambda not managed in the version control.
Use this excellent script.
# This block is not necessary if you set a default profile export AWS_DEFAULT_PROFILE=xxxxx export AWS_DEFAULT_REGION=ap-northeast-1 export AWS_DEFAULT_OUTPUT=text # Run bash download_all_lambda_functions.sh
Script says, "Completed Downloading all the Lamdba Functions!" but just threw the task in the background, so it hasn't finished.
No signal is said when all background tasks are finished.
So, I considered it complete when the download task stops and the number of zip files matches the functions.
A zip file for each function is downloaded in lambda_functions/*.
It's a bit annoying to get them by region.
I recommend separating the download destination folder for each region.
Search for foobar
cd lambda_functions for file in *.zip; do res=`zipgrep -n foobar $file` if [ -n "$res" ]; then echo "x:$file"; echo "$res"; else echo "o:$file"; fi done
x:aaaa-checker.zip lambda_function.py:30: target = "foobar", o:bbbbb-deleter.zip o:ccccc-notifier.zip x:ddddd-test.zip lambda_function.py:21: print("foobar"), ...
find . /lambda_functions -name '*.zip' | xargs -I file zipgrep foobar file
This command was insufficient for me because it did not know the ZIP where the keyword was detected.
If Lambda comes with libraries and .env environment, grep will take a long time.