Last active
July 12, 2017 17:57
-
-
Save jcttrll/c7b8cdb8eca938aeb86094c34ab1afb8 to your computer and use it in GitHub Desktop.
Usage: lambda-storage-calc.sh --region <aws-region>
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 -e | |
if [ $# -ne 2 -o ! "$1" = "--region" ]; then | |
echo "Usage: ${0##*/} --region <aws-region>" 2>&1 | |
exit 1 | |
fi | |
AWS_REGION="$2" | |
AWS_OPTIONS+=" --region $AWS_REGION --output json" | |
lambdas=($(aws $AWS_OPTIONS lambda list-functions | jq -r '.Functions[].FunctionName')) | |
for lambda in "${lambdas[@]}"; do | |
aws $AWS_OPTIONS lambda list-versions-by-function --function-name "$lambda" | | |
jq -r '.Versions[] | "\(.LastModified)\t\(.Version)\t\(.CodeSize)\t\(.Description)"' | sort | | |
awk -v lambda="$lambda" ' | |
{ | |
date = $1; | |
version = $2; | |
size = $3; | |
sub("[^\t]+\t[^\t]+\t[^\t]+\t", ""); | |
description = $0; | |
count++; | |
overallSize += size; | |
if (version == "$LATEST") { | |
latest = size; | |
} | |
printf("\t%s %7s %10d bytes: %s\n", date, version, size, description); | |
} | |
END { | |
if (count > 1) { | |
overallSize -= latest; | |
} | |
v = count == 1 ? "version" : "versions"; | |
printf("%s - %d %s, %d total bytes\n", lambda, count, v, overallSize); | |
} | |
' | tac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that, if necessary, you can pass options to the AWS CLI commands by setting
AWS_OPTIONS
outside the script, like: