DEV Community

Cover image for How to check what code is currently running in your lambda when UI Console does not allow viewing or editing it
Davide de Paolis
Davide de Paolis

Posted on

How to check what code is currently running in your lambda when UI Console does not allow viewing or editing it

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?

Your Lambda is too big

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.

What is running in the lambda? When and what was deployed last?

(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."

How can you check that code then?

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
Enter fullscreen mode Exit fullscreen mode

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!

Happy debugging.

happy debugging


Photo by Dmitry Ratushny on Unsplash

Top comments (2)

Collapse
 
rolfstreefkerk profile image
Rolf Streefkerk

What I do to circumvent this issue is to create a lambda layer with dependencies.

My main code base will never reach that 3Mbyte limit, so you can always view it in the online code editor and do edits there if you need.

Collapse
 
dvddpl profile image
Davide de Paolis

I just finishing another post regarding how to reduce the size of the uploaded package ( with proper bundling is still quite hard to reach that limit).
But I must say I haven-t considered Lambda Layers for that, haven-t tried them yet, definitely worth mention this option. Thanx!