Recently I wanted to get a count of Lambdas in AWS across multiple accounts. The following script parses a list of accounts (from the saml2aws account format) and iterates through them. It prints out a file for each account (with the name of each lambda function in that account, one per line).
#!/bin/bash
# file: aws-list-all-lambdas.sh
# Author: Steve Stonebraker
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
OUTPUT_PATH="${SCRIPTPATH}/lambdas"
mkdir -p "$OUTPUT_PATH"
cd "$OUTPUT_PATH" || exit
aws_profiles=$(grep '\[' ~/.aws/credentials | tr -d '[' | tr -d ']')
for profile in ${aws_profiles}
do
OUTFILE="${OUTPUT_PATH}/lambda_${profile}.txt"
echo "[*] - Processing profile [$profile]"
aws --profile "${profile}" \
lambda list-functions \
| jq -r '.Functions[].FunctionName' \
| sort > "${OUTFILE}"
done
cat "${OUTPUT_PATH}/lambda*.txt" | sort | uniq > "${OUTPUT_PATH}/all_lambdas.txt"
echo "[*] - files located at ${OUTPUT_PATH}"
echo "[*] - combined output path:"
echo "${OUTPUT_PATH}/all_lambdas.txt"