Created
September 20, 2023 14:20
-
-
Save indifferentcats/d6b2a513816ce32c3702fa00ab1eb237 to your computer and use it in GitHub Desktop.
Get All AWS Lambda runtimes in CSV format for easy sorting and filtering . Optional argument is a list of profiles to query. Only $LATEST versions are captured. Requires all AWS profiles be active (tough to do for sso), or at least any that are listed on the command line if provided. Needs AWS CLI 2.x and jq.
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/bash | |
profiles="$@" | |
if [ -z "$profiles" ]; then | |
profiles="$(aws configure list-profiles)" | |
else | |
echo "Restricting run to these profiles $profiles" | |
fi | |
results_folder=results | |
mkdir -p $results_folder | |
regions="us-east-1" | |
csv=$results_folder/all_functions.csv | |
if [ ! -f $csv ]; then | |
echo "Profile,Account,Region,Runtime,FunctionName" > $csv | |
fi | |
for profile in $profiles; do | |
for region in $regions; do | |
printf "Getting functions in $region for $profile profile..." | |
output=$results_folder/functions_${profile}_$region.json | |
if [ -f $output ]; then | |
echo "cached." | |
else | |
aws --profile $profile lambda list-functions \ | |
--region $region > $output | |
if [ $? -ne 0 ]; then | |
echo | |
echo "An Error occurred in the above statement" | |
rm $output | |
else | |
echo "done" | |
cat $output | jq --arg profile "$profile" -r '.Functions[] | .FunctionArn |= . / ":" | [$profile,.FunctionArn[4], .FunctionArn[3],.Runtime,.FunctionName] | @csv ' >> $csv | |
fi | |
fi | |
done | |
done | |
echo "See CSV summary in $csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment