question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

M1 Mac (Apple Silicon): AWS SAM Golang lambda debugging does not work

See original GitHub issue

Desktop (please complete the following information):

  • OS: macOS BigSur 11.5.2 (M1)
  • VS Code version: 1.16
  • AWS Toolkit extension version: 1.29.0
  • AWS SAM cli version: 1.31.0
  • Go version: 1.16.8 (also tried this with the latest 1.17.1, but has the same issue)
  • vscode-go version: 0.27.2

How to get my AWS SAM initiated local debugging of lambda’s written in Go working?

Summary of the problem After creating a plain vanilla AWS SAM application with sam init for golang, and then using the code lens to create an AWS SAM template file based debug configuration, I get the following error when trying to debug the lambda code. Running the code without debugging works.

2021-09-11 10:55:02 [INFO]: The Delve repo was not found in your GOPATH. Downloading in a temporary directory...
2021-09-11 10:55:03 [INFO]: Preparing to debug locally: Lambda "hello-world"
2021-09-11 10:55:03 [INFO]: Building SAM application...
2021-09-11 10:55:03 [INFO]: Running command: (not started) [/opt/homebrew/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkeYZ6BB/output --template /Users/user1/dev/godev/aws/lambdas/hello-world/hello-world/app___vsctk___template.yaml --base-dir /Users/user1/dev/godev/aws/lambdas/hello-world/hello-world]
2021-09-11 10:55:03 [INFO]: Building codeuri: /Users/user1/dev/godev/aws/lambdas/hello-world/hello-world runtime: go1.x metadata: {} functions: ['helloworld']

2021-09-11 10:55:03 [INFO]: Running GoModulesBuilder:Build

2021-09-11 10:55:03 [INFO]: 
Build Succeeded

2021-09-11 10:55:03 [INFO]: 
Built Artifacts  : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctkeYZ6BB/output
Built Template   : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctkeYZ6BB/output/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke -t ../../../../../../../private/tmp/aws-toolkit-vscode/vsctkeYZ6BB/output/template.yaml
[*] Deploy: sam deploy --guided --template-file ../../../../../../../private/tmp/aws-toolkit-vscode/vsctkeYZ6BB/output/template.yaml
    

2021-09-11 10:55:04 [INFO]: Build complete.
2021-09-11 10:55:04 [INFO]: Starting SAM application locally
2021-09-11 10:55:05 [INFO]: AWS.running.command
Invoking hello-world (go1.x)
Requested to skip pulling images ...

Mounting /tmp/aws-toolkit-vscode/vsctkeYZ6BB/output/helloworld as /var/task:ro,delegated inside runtime container
START RequestId: 7c546e9e-8558-4fde-8dd6-fc6946034850 Version: $LATEST
API server listening at: [::]:5858
2021-09-11T00:55:07Z info layer=debugger launching process with args: [/var/task/hello-world]
2021-09-11 10:55:07 [INFO]: Waiting for SAM application to start...
could not launch process: fork/exec /var/task/hello-world: function not implemented
2021/09/11 00:55:07 exit status 1
time="2021-09-11T00:55:07.765" level=error msg="Init failed" InvokeID= error="Runtime exited with error: exit status 1"
time="2021-09-11T00:55:07.773" level=error msg="INIT DONE failed: Runtime.ExitError"
2021-09-11 10:55:08 [INFO]: Attaching debugger to SAM application...

Command stopped: "sam local invoke"

From the output listed above, it seems to me that when using the debugger, it thinks that the function is not implemented. 2021-09-11 10:55:07 [INFO]: Waiting for SAM application to start… could not launch process: fork/exec /var/task/hello-world: function not implemented

Running the above lambda from command line with sam build && sam local invoke works.

Other considerations

  • Go debugging works for vanilla go apps (non lambdas)
  • Go lambdas run successfully with sam local invoke.

Steps to reproduce

  1. Create a new AWS SAM application using Go with sam init.
  2. Select the Hello world template.
  3. In the main.go file, create a debug configuration from the code lens provided by the AWS Toolkit and associated with the handler.
  4. Set a breakpoint and start debugging.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
edyesedcommented, Sep 18, 2021

I concur that file sharing is not the root of the issue you’re experiencing. In my docker file share I had /Users and /tmp . This had been functional for me historically with debugging Sam apps with vscode. This week I need to add /private as well 🤷. I recalled the error surfaced was function not implemented, but perhaps I am mistaken or this error appears for multiple conditions. Either way, file sharing is working for you and not the root of your issue.

1reaction
edyesedcommented, Sep 17, 2021

I had this issue. Check your filesharing preferences in docker. I had shared /tmp , though after some update to docker this stopped working. I had to additionally share /private. You can find the file sharing preferences under Docker -> Preferences -> Resources -> File Sharing . Make sure you have /tmp and /private in there. You can test with docker run -it /tmp/aws-toolkit-vscode/vsctkeYZ6BB/output/helloworld:/tmp/goo ubuntu:latest /bin/bash . If ls /tmp/goo inside your container comes up with the empty set, docker filesharing a very probable culprit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Golang AWS SAM lambda Function debugging is not working ...
Golang AWS SAM lambda Function debugging is not working on M1 Mac ... When trying to debug simple SAM, I'm receiving the following...
Read more >
AWS SAM With Apple M1
However, after switching to M1 Macs, the execution step started failing, as it could not find one of the script files. In the...
Read more >
Installing the AWS SAM CLI - AWS Serverless Application Model
This section describes how to install the AWS SAM CLI on macOS, Windows, and Linux.
Read more >
Run AWS Sam for Golang on Mac M1 - ahmet ozer
Amazon lambda is a widely used serverless platform, it supports a variety of programming languages but only one of them interests me which ......
Read more >
Apple Silicon M1, AWS SAM-CLI, Docker, MySql, and .netcore ...
In summary, it is possible to run your local AWS-SAM + Amplify + .netcore Lambda + MySql environment on an Apple silicon M1....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found