Backing up AWS lambda functions

There might be a built-in method to do so, but I haven’t found one. I wanted to download packages of all the lambda files I have in AWS and ended up creating a script to do it. Feel free to copy. Don’t forget to chmod u+x … 🙂


# Get all the function names (assuming my region is us-east-1)
list=`aws lambda list-functions --region us-east-1 | jq -r .Functions[].FunctionName | perl -pe 's/\n/ /g'`

# For each lambda function, get the function's download url and download it
for val in $list; do
url=`aws lambda get-function --region us-east-1 --function-name $val --profile lambda_user | jq -r .Code.Location`
wget $url

# Rename all the downloaded files by removing the long url params and adding a zip extension
find . -type f -name '*versionId*' -print0 |
while IFS= read -d '' file_name; do
newname=`echo $file_name | perl -pe 's/^(.+)\?versionId=.+/\'`
mv "$file_name" "$newname"

Leave a Reply

Your email address will not be published. Required fields are marked *