aws / aws-lambda-runtime-interface-emulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A port for debugging and stepping into the code

muhamadto opened this issue · comments

When running the service locally it would be helpful if we can step into the code. I believe this is possible when using SAM but not when we using container images and running the function using RIE.

for example when running usual java apps we can add -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 to the run command then listen to 5005 to be able to step into the code.

Maybe a possible way would be to add a --debug-port option to the /usr/bin/aws-lambda-rie command

Hey muhamadto thank you for the suggestion.

So you have a debugger within the container running and you want a port opened to be able to connect to it?

You can achieve this by modifying the Docker command you use to startup the container, exposing the containers ports.

E.g.

docker run -p 9000:8080 -p 5005:5005 myfunction:latest

For additional documentation on exposing ports see

https://docs.docker.com/engine/reference/run/#expose-incoming-ports

Hey @bodelsc Thanks for getting back to me. I having not looked into this in a year but from memory the problem is not mapping the port. The problem is that/usr/bin/aws-lambda-rie does not provide an option for running in debug mode. Something similar to running SAM with -d option

sam local invoke -d 5858 <function logical id>

For the mapping you shared to work, the entrypoint file needs to look like this — please note the -d 5005.

#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/local/bin/aws-lambda-rie /usr/local/bin/java aws-lambda-ric -d 5005 $@
else
  exec /usr/local/bin/java aws-lambda-ric $@
fi 

Hey @muhamadto

Thank you for the reply and the detailed explanation.

I looked into how AWS SAM CLI is implementing the debugging ports[1].
If it is an interpreted language it passes the debugging options onto the language's runtime, e.g. JVM[2], Node.js[3].
And if it is a compiled language they AWS SAM CLI uses a debugger(which I believe AWS SAM CLI installs into the container), such as delve[4] for Go[5].

You can accomplish this behaviour without AWS SAM CLI by altering the Docker entrypoint and environment variables yourself.

The AWS Lambda Runtime Interface Emulator is for emulating Lambda’s Runtime and Extensions APIs, so accepting debugging options and passing them onto debuggers or language runtimes would be outside it's remit, so I am going to close this issue.

I think a better place to ask for debugging support to be added is the AWS Lambda Base Images[6]. Which could be toggled on and off by environment variable such as AWS_LAMBDA_DEBUG_PORT, which AWS SAM CLI could then use.

@bodelsc thanks

@muhamadto did you create a follow-up issue regarding this in the repos mentioned? I would be interested in this as well.

@niklaswallerstedt here we go. maybe you can vote it up and add your requirement to it too.

you can add into environment variable

NODE_OPTIONS='--inspect-brk=0.0.0.0:9229'