Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download All Lambda Functions
# Parallelly download all aws-lambda functions
# Assumes you have ran `aws configure` and have output-mode as "text"
# Works with "aws-cli/1.16.72 Python/3.6.7 Linux/4.15.0-42-generic botocore/1.12.62"
download_code () {
local OUTPUT=$1
aws lambda get-function --function-name $OUTPUT --query 'Code.Location' | xargs wget -O ./lambda_functions/$OUTPUT.zip
}
mkdir -p lambda_functions
for run in $(aws lambda list-functions | cut -f 6 | xargs);
do
download_code "$run" &
done
echo "Completed Downloading all the Lamdba Functions!"
# If you want to download only ones with specific prefix
# https://github.com/sambhajis-gdb/download_all_lambda_function/blob/master/get_lambda_with_prefix.sh
# Credits to https://stackoverflow.com/users/6908140/sambhaji-sawant for the
@nemani

This comment has been minimized.

Copy link
Owner Author

@nemani nemani commented Dec 10, 2018

This small bash script downloads the zip for each lambda function in your AWS account.

You need to create a new IAM user in AWS Console, put the access keys into aws configure (set output mode to "text"), then run the script.

@TheNetJedi

This comment has been minimized.

Copy link

@TheNetJedi TheNetJedi commented Feb 4, 2019

Fantastic!

@Selimcse98

This comment has been minimized.

Copy link

@Selimcse98 Selimcse98 commented Jun 14, 2019

Awesome! It worked nicely. Thanks a lot!

@Ton-Anne

This comment has been minimized.

Copy link

@Ton-Anne Ton-Anne commented Jun 20, 2019

"doth" line 11 might be a typo?
Other than that very nice! Thanks a lot.

@arorasahil1207

This comment has been minimized.

Copy link

@arorasahil1207 arorasahil1207 commented Oct 7, 2019

I am new here can you tell me where you have put the access key/token ?

@nemani

This comment has been minimized.

Copy link
Owner Author

@nemani nemani commented Oct 7, 2019

@arorasahil1207 as mentioned aws configure should do the trick

@arorasahil1207

This comment has been minimized.

Copy link

@arorasahil1207 arorasahil1207 commented Oct 14, 2019

I don't know how to work with bash can you please elaborate so that i can understand the same,thanks in advance

@nemani

This comment has been minimized.

Copy link
Owner Author

@nemani nemani commented Oct 14, 2019

First you need a bash shell.

Next you need to install aws cli which allows you to interact with AWS services via the CLI and bash scripts.

https://docs.aws.amazon.com/cli/latest/userguide/install-linux-al2017.html

Once this is done, you need to run the command aws configure to setup the initial configuration.

It will ask you inputs like text mode and the IAM config keys to use with AWS CLI.

Then you can follow the script above.

@SIVA451

This comment has been minimized.

Copy link

@SIVA451 SIVA451 commented Apr 13, 2020

For me, it showing as an empty folder while unzipping it in windows OS.

@pgorpuni

This comment has been minimized.

Copy link

@pgorpuni pgorpuni commented May 6, 2020

I am getting below error. I did AWS configure also.
An error occurred (ValidationException) when calling the GetFunction operation: 1 validation error detected: Value 'DB_User:' at 'functionName' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-.]+)(:($LATEST|[a-zA-Z0-9-]+))?
xargs: wget: No such file or directory

@nemani

This comment has been minimized.

Copy link
Owner Author

@nemani nemani commented May 7, 2020

@pgorpuni looks like the error is due to a lambda named 'DB_User'. The regex constraints for the name are by AWS and this does not match it. Don't think it is an error with the script. Try changing the name of the lambda.

I am getting below error. I did AWS configure also.
An error occurred (ValidationException) when calling the GetFunction operation: 1 validation error detected: Value 'DB_User:' at 'functionName' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-.]+)(:($LATEST|[a-zA-Z0-9-]+))?
xargs: wget: No such file or directory

For me, it showing as an empty folder while unzipping it in windows OS.

@SIVA451 sorry I dont use windows so cant help by writing a script for it.
The above script is meant for bash (or similiar like zsh) shells which are commonly on linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.