Skip to content

Instantly share code, notes, and snippets.

@TheNetJedi
Last active November 8, 2023 15:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TheNetJedi/0847ba0ec1da9879b4fa1d8f3276b004 to your computer and use it in GitHub Desktop.
Save TheNetJedi/0847ba0ec1da9879b4fa1d8f3276b004 to your computer and use it in GitHub Desktop.
Bash script to download all your Lambda functions.
#!/usr/bin/env bash
#You need to have aws-cli installed and configured
#Credits to Reddit user u/aa93 for the suggestions
mkdir code
aws lambda list-functions | \
grep FunctionName | \
cut -d '"' -f4 | \
while read -r name; do
aws lambda get-function --function-name $name | tail -n 3 | egrep -o 'https?://[^ ]+' | sed 's/"//' | xargs wget -O ./code/$name.zip
done
@kitobelix
Copy link

I had to patch it because the output from get-function doesn't always came in the same order. I used jq as: aws lambda get-function --function-name $name | jq -r '.Code.Location' | xargs wget -O ./code/$name.zip in line 10 and it worked flawlessly.

Thank you very much!

@drajesh209
Copy link

Working flawlessly. Thanks for sharing

@yyano
Copy link

yyano commented Dec 29, 2019

I used export source code w/ function Configurations.
aws lambda get-function --function-name $name | tee ./code/$name.json | jq -r '.Code.Location' | xargs wget -O ./code/$name.zip

Thank you!

@panchuprodhan
Copy link

It's not working for me, just generating the folder "code"; nothing else.
Thanks.

@Sankyyuu
Copy link

Using Wget didnt worked really well for me i instead replaced it by curl and it works well
aws lambda get-function --function-name $name | tee ./code/$name.json | jq -r '.Code.Location' | xargs curl --output ./code/$name.zip

@RaphaMiranda
Copy link

RaphaMiranda commented Nov 11, 2022

This worked for me using git-bash terminal on windows.

#!/usr/bin/env bash
#You need to have aws-cli installed and configured
#You need to have CURL installed
#Credits to Reddit user u/aa93 for the suggestions

mkdir -p code
aws lambda list-functions | \
grep FunctionName | \
#Select only matching prefix functions
grep <prefix> | \
cut -d '"' -f4 | \
while read -r name; do
    aws lambda get-function --function-name $name | tee ./code/$name.json | egrep -o 'https?://[^ ]+' | sed 's/"//' | xargs curl --output ./code/$name.zip
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment