Reputation: 1120
I have a generic SAM application generated by AWS Toolkit. My end goal is to debug my go application line by line.
Sorry if this question gets too long, but I have tried my best to add as few relevant details as possible, while trying to make sure I don't miss anything important.
I am using the default launch.json
configurations generated by the Toolkit:
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "sunflowers:HelloWorldFunction (go1.x)",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "HelloWorldFunction"
},
"lambda": {
"payload": {},
"environmentVariables": {},
"runtime": "go1.x"
}
},
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "API sunflowers:HelloWorldFunction (go1.x)",
"invokeTarget": {
"target": "api",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "HelloWorldFunction"
},
"api": {
"path": "/hello",
"httpMethod": "get",
"payload": {
"json": {}
}
},
"lambda": {
"runtime": "go1.x"
}
}
]
}
But when I run sunflowers:HelloWorldFunction (go1.x)
, I get the following error in the AWS Toolkit output:
could not launch process: fork/exec /var/task/hello-world: function not implemented
Full error Log:
2022-08-04 18:41:12 [INFO]: Preparing to debug locally: Lambda "hello-world"
2022-08-04 18:41:12 [INFO]: Building SAM application...
2022-08-04 18:41:12 [INFO]: Command: (not started) [/opt/homebrew/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctky6JmVn/output --template /Users/varungawande/playground/goLambdaDebug/sunflowers/template.yaml]
2022-08-04 18:41:13 [INFO]: Your template contains a resource with logical ID "ServerlessRestApi", which is a reserved logical ID in AWS SAM. It could result in unexpected behaviors and is not recommended.
2022-08-04 18:41:13 [INFO]: Building codeuri: /Users/varungawande/playground/goLambdaDebug/sunflowers/hello-world runtime: go1.x metadata: {} architecture: x86_64 functions: HelloWorldFunction
2022-08-04 18:41:13 [INFO]: Running GoModulesBuilder:Build
2022-08-04 18:41:13 [INFO]:
Build Succeeded
2022-08-04 18:41:13 [INFO]:
Built Artifacts : ../../../../../private/tmp/aws-toolkit-vscode/vsctky6JmVn/output
Built Template : ../../../../../private/tmp/aws-toolkit-vscode/vsctky6JmVn/output/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke -t ../../../../../private/tmp/aws-toolkit-vscode/vsctky6JmVn/output/template.yaml
[*] Test Function in the Cloud: sam sync --stack-name {stack-name} --watch
[*] Deploy: sam deploy --guided --template-file ../../../../../private/tmp/aws-toolkit-vscode/vsctky6JmVn/output/template.yaml
2022-08-04 18:41:14 [INFO]: Build complete.
2022-08-04 18:41:14 [INFO]: Starting SAM application locally
2022-08-04 18:41:14 [INFO]: AWS.running.command
Invoking hello-world (go1.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-go1.x:rapid-1.53.0-x86_64.
Mounting /tmp/aws-toolkit-vscode/vsctky6JmVn/output/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 8cc3eb7a-20f2-4599-81bc-2f29f8d02102 Version: $LATEST
API server listening at: [::]:5858
2022-08-04T13:11:16Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2022-08-04T13:11:16Z info layer=debugger launching process with args: [/var/task/hello-world]
2022-08-04 18:41:16 [INFO]: Waiting for SAM application to start...
could not launch process: fork/exec /var/task/hello-world: function not implemented
2022/08/04 13:11:16 exit status 1
04 Aug 2022 13:11:16,067 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID=
API server listening at: [::]:5858
2022-08-04T13:11:16Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2022-08-04T13:11:16Z info layer=debugger launching process with args: [/var/task/hello-world]
could not launch process: fork/exec /var/task/hello-world: function not implemented
2022/08/04 13:11:16 exit status 1
END RequestId: 0dcb2785-a232-41aa-8f78-f61c82add96b
REPORT RequestId: 0dcb2785-a232-41aa-8f78-f61c82add96b Init Duration: 1.26 ms Duration: 838.60 ms Billed Duration: 839 ms Memory Size: 128 MB Max Memory Used: 128 MB
2022-08-04 18:41:17 [INFO]: Attaching debugger to SAM application...
Command stopped: "sam local invoke"
2022-08-04 18:41:23 [ERROR]: Retry limit reached while trying to attach the debugger.
2022-08-04 18:41:23 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
sam local start-api
and sam local invoke
still work.
The path they mounted at /tmp/aws-toolkit-vscode/vsctky6JmVn/output/HelloWorldFunction
does have the file they're looking for.
❯ tree /tmp/aws-toolkit-vscode/vsctky6JmVn/output/HelloWorldFunction
/tmp/aws-toolkit-vscode/vsctky6JmVn/output/HelloWorldFunction
└── hello-world
The hello-world
program does have a main function:
package main
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
var (
// DefaultHTTPGetAddress Default Address
DefaultHTTPGetAddress = "https://checkip.amazonaws.com"
// ErrNoIP No IP found in response
ErrNoIP = errors.New("No IP in HTTP response")
// ErrNon200Response non 200 status code in response
ErrNon200Response = errors.New("Non 200 Response found")
)
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
str := "Hello World"
str = exclaim(str)
for i := 3; i < 30; i++ {
str = exclaim(str)
fmt.Println(str, "at", i)
}
resp, err := http.Get(DefaultHTTPGetAddress)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
if resp.StatusCode != 200 {
return events.APIGatewayProxyResponse{}, ErrNon200Response
}
ip, err := ioutil.ReadAll(resp.Body)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
if len(ip) == 0 {
return events.APIGatewayProxyResponse{}, ErrNoIP
}
return events.APIGatewayProxyResponse{
Body: fmt.Sprintf("Hello, %v", string(ip)),
StatusCode: 200,
}, nil
}
func main() {
lambda.Start(handler)
}
func exclaim(str string) string {
return str + "!"
}
Note: I'm on a Mac, using the M1 chip(Arch: arm64) but the build-file is being executed for x86-64
.
hello-world: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=O4tsTAbXATrthCbExZYS/IcUitw8QuK2KVYZ9ln5Y/QZl7mLeZv6TDrrYMwafh/81ITMlD5ZHrz3gae1BfY, with debug_info, not stripped```
Since it can find the file, Does this mean that the executor can't find the main?
Upvotes: 2
Views: 920