Debug your Code
How It Works
You can use the mug debug
command to locally run the generated functions or whatever modifications you have made. The command will simply do the following:
- Generate a Makefile for the resource or function group.
- Build binaries in the
debug
folder usingmake debug
defined in theMakefile
. - Generate a
template.yml
later required by aws-sam-cli to provide the API Gateway. - Create a local docker network for aws-sam and dynamodb to talk to each other.
- Start/ Restart a daemon of
amazon/dynamodb-local
container. - Create the tables in the database.
- Start the API with
sam local start-api
.
Step through Code
To be able to debug your code step by step, you have to define the -r
remoteDebugger flag. This tells mug to initiate a delve debug process. This by default runs on port 5986, however you can overwrite this by defining the -p
debugPort flag.
When you start with the remote debugger enabled you can easily step through your functions using breakpoints etc. Make sure you have a propper launch configuration beforehand. For Visual Studio Code it may look like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "lambda debug",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${file}",
"env": {},
"args": [],
},
]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Debugging bigger projects
In case your projects get a little bigger, you may have no interest in generating, building and running a debug process for the entire project, but only for a couple of your resources or function groups.
You can do so by specifying a comma separated list of resources/ function groups with the -l
list flag. mug will then only run the generation and build process for those defined.