Have you ever been debugging a Lambda function and just after checking CloudWatch for the logs, you went to the UI console to see what the Lambda is doing at a specific line and found out you can´t see anything?
Of course, I am NOT saying you should be fiddling with the code directly on the console and deploy to production straight away, but sometimes it is handy to at least see what it´s running, especially if on your git master the code contains already a lot of new feature-merges.
(Spoiler: Tagging every deployment in Git, also helps)
If you are using Node and your lambda is not huge (normally we choose single purposed lambdas - something like one per endpoint ) you should definitely be able to see the code in the console. But, especially if you have lots of dependencies, it is easy to reach the 3M limit and having the console just showing the following warning:
"The deployment package of your Lambda function "xyz" is too large to enable inline code editing. However, you can still invoke your function."
The console does not allow you to see it, and it does not provide you with any button do download the content of the lambda.
What to do?
Well, just use
aws lambda get-function cli command.
If you try that though, it is a bit disappointing because it just returns all information about the function or function version, with a link to download the deployment package that's valid for 10 minutes, and that means you need to copy that link and navigate to it, to find out you don´t see any code... or you can pipe that URL directly to curl to stuff the data into a zip file!
aws lambda get-function --function-name YOUR_FUNCTION_NAME --query 'Code.Location' | xargs curl -o YOUR_FUNCTION_NAME.zip
Then it´s just a matter of
unzip YOUR_FUNCTION_NAME.zip and you have the folder with all the content of the deployed package!
Photo by Dmitry Ratushny on Unsplash