Q:

Download AWS Lambda source package as Zip from AWS CLI

I want to download AWS Lambda source package as Zip. I know that there is an option to download lambda function as SAM file or deployment package in lambda console. But I don't have access to AWS console in the production environment.
See the attached screens.

Below are the two available options.

I want to do same functionality in AWS CLI with minimum shell script commands. After downloading the lambda source in zip format, I will create lambda function in production environment via AWS CLI.
aws lambda create-function --region [AWSREGION] --function-name [FUNCTION] --zip-file fileb://[ZIPFILE] --role [ROLEARN] --handler [FILENAME].lambda_handler  --description="[FUNCTIONDESCRIPTION]"  --runtime [RUNTIME] --timeout [TIMEOUT] --memory-size [MEMORYSIZE] --profile [PROFILENAME]

Please help me with this matter, help in linux shell script commands will be highly appreciated.

A:

You may find the answer here :
Download an already uploaded Lambda function
A simple bash solution is also provided at https://gist.github.com/nemaniarjun/defdde356b6678352bcd4af69b7fe529
# 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 | head -n 1 | cut -f 2 | xargs wget -O ./lambda_functions/$OUTPUT.zip  
}

mkdir lambda_functions
for run in $(aws lambda list-functions | cut -f 6 | xargs);
doth
    download_code "$run" &
done

Edit: 
  Credits to the original author. Just sharing the code since the URL may get unreachable later.

