Shahin's Blog

Shahin's Blog

TIL: Download AWS Lambda Function

TIL: Download AWS Lambda Function

Shahin's photo
·Aug 29, 2022·

2 min read


CI/CD pipelines or processes (human error) can mess up, and you miss an essential update in your Lambda function. Of course, if the Lambda is small enough, you can see the actual code in an excellent editor on the console. But if that's not the case, it'll show you a message like:

The deployment package of your Lambda function "YOUR_FUNCTION" is too large to enable inline code editing. However, you can still invoke your function.

Well, that's fortunate that the world is not limited to fancy graphical user interfaces. When one of my colleagues suggested checking the code, I researched, and learned that aws lambda get-function is almost what I'm looking for. The method, however, does not actually get the function but returns enough information to you. So I turned it into a shell function, to take care of this in the future:

function download_aws_lambda {
    mkdir -p $1 && cd $1
    aws lambda get-function --function-name $1 | jq '.Code.Location' | xargs curl | bsdtar -xvf-
    cd -

Put it in your shell's rc file and tell it the Lambda function's name that you need, and it'll create a directory for you with that name containing the deployed functions source codes or binaries. The call would be like:

download_aws_lambda MY_FUNCTION


You see, I'm using bsdtar instead of the usual and known unzip. That's because unzip according to its man:

Archives read from standard input are not yet supported, except with funzip (and then only the first member of the archive can be extracted).

Share this