Original post

I’ve been tinkering around with for a little bit now, and I have been playing with the idea to develop some serverless applications using . However, my experience in debugging with using VSCode have been not so great, at least when compared to NodeJS.

In NodeJS, I write some code that starts with exports.handler, use the following template as the template.yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  MyFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: index.handler
      CodeUri: ./
      Runtime: nodejs8.10

Run sam local invoke -d 5858 -e some-event.json, attach the debugger to the process using the vscode launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
    "name": "Attach to SAM CLI",
    "type": "node",
    "request": "attach",
    "address": "localhost",
    "port": 5858,
    "localRoot": "",
    "remoteRoot": "/var/task",
    "protocol": "inspector",
    "stopOnEntry": false
    }
  ]
}

and I’m ready to go.

In Go however, this is not all to easy to accomplish. I start off with a simple Go lambda application using sam init --runtime go1.x.

Running the lambda locally using sam was not a problem – I ran the commands as below.

make build
touch event.json # this I followed a standard API event structure
sam local invoke HelloWorldFunction -e event.json

{"statusCode":200,"headers":null,"multiValueHeaders":null,"body":"Hello, 2.49.15.103n"}

With that, I refer to the documentation written here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-golang.html

After setting up everything, including recompiling the delve debugger, and setting delve api to 2 (or not, it does not matter), I would always get this error message:

sam local invoke HelloWorldFunction -e event.json -d 5986 --debugger-path ./tmp --debug-args "-delveAPI=2"
Invoking hello-world (go1.x)
2020-01-14 17:06:03 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:go1.x Docker container image......
Mounting /repos/go-lambda-sam/hello-world as /var/task:ro,delegated inside runtime container
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5986
2020-01-14T13:06:07Z info layer=debugger launching process with args: [/var/task/hello-world]

and with that (I have also tried removing and reinstalling golang), I gave up doing inline debugging with go on AWS SAM CLI. I am wondering if anyone has other experiences dealing with this before, and I wonder why is setting up tooling for go more troublesome that it needs to be, or that I am looking at the wrong places.