awsdocs/aws-sam-developer-guide

Golang Debugging - Error starting Mock Server

rsbethke opened this issue · 1 comments

I've been trying to get step through debugging working following the guide on MacOS 11.1. Starting with the basic hello-world template I'm able to build the project and run it locally. If I follow the guide and build delve and the application as instructed, I receive an error message stating Error starting mock server: fork/exec /var/rapid/init: no such file or directory are these instructions missing some details around setup?

My project is structured as:

.
├── .aws-sam
│   ├── build
│   │   ├── HelloWorldFunction
│   │   │   └── hello-world
│   │   ├── delve
│   │   │   └── dlv
│   │   └── template.yaml
│   └── build.toml
├── Makefile
├── README.md
├── hello-world
│   ├── go.mod
│   ├── go.sum
│   ├── main.go
│   └── main_test.go
└── template.yaml

The template file has not been changed from the sample application.

I've added the following debug section to the Makefile:

.PHONY: debug
debug:
	GOARCH=amd64 GOOS=linux go build -o .aws-sam/build/delve/dlv github.com/go-delve/delve/cmd/dlv
	GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o .aws-sam/build/HelloWorldFunction ./hello-world
	sam local start-api --debug -d 5986 --debugger-path .aws-sam/build/delve --debug-args "-delveAPI=2"
GOARCH=amd64 GOOS=linux go build -o .aws-sam/build/delve/dlv github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o .aws-sam/build/HelloWorldFunction ./hello-world
sam local start-api --debug -d 5986 --debugger-path .aws-sam/build/delve --debug-args "-delveAPI=2"
2021-01-19 08:17:10,655 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-01-19 08:17:10,788 | local start-api command is called
2021-01-19 08:17:10,793 | No Parameters detected in the template
2021-01-19 08:17:10,818 | 2 resources found in the template
2021-01-19 08:17:10,819 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2021-01-19 08:17:10,825 | No Parameters detected in the template
2021-01-19 08:17:10,845 | 2 resources found in the template
2021-01-19 08:17:10,845 | Found '1' API Events in Serverless function with name 'HelloWorldFunction'
2021-01-19 08:17:10,845 | Detected Inline Swagger definition
2021-01-19 08:17:10,845 | Lambda function integration not found in Swagger document at path='/hello' method='get'
2021-01-19 08:17:10,845 | Found '0' APIs in resource 'ServerlessRestApi'
2021-01-19 08:17:10,845 | Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2021-01-19 08:17:10,846 | 1 APIs found in the template
2021-01-19 08:17:10,847 | Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2021-01-19 08:17:10,847 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2021-01-19 08:17:10,847 | Localhost server is starting up. Multi-threading = False
2021-01-19 08:17:10  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2021-01-19 08:17:14,834 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "Connection": "keep-alive", "Cookie": "_xsrf=2|2b874059|3eb43ef1dfc6f978fbbc0ad98fb47dc3|1609784256; username-127-0-0-1-8888=\"2|1:0|10:1610483981|23:username-127-0-0-1-8888|44:NTRjYjg1MGQwZTFhNDE4YWI3NDY3Y2I5ZGQ2YTNiODM=|85f1aa629160bd9a7b67f2336db4a7934bcdc8ed6d2be3458bd51ac59be7a3db\"", "Host": "127.0.0.1:3000", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "Connection": ["keep-alive"], "Cookie": ["_xsrf=2|2b874059|3eb43ef1dfc6f978fbbc0ad98fb47dc3|1609784256; username-127-0-0-1-8888=\"2|1:0|10:1610483981|23:username-127-0-0-1-8888|44:NTRjYjg1MGQwZTFhNDE4YWI3NDY3Y2I5ZGQ2YTNiODM=|85f1aa629160bd9a7b67f2336db4a7934bcdc8ed6d2be3458bd51ac59be7a3db\""], "Host": ["127.0.0.1:3000"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/hello", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "127.0.0.1:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/hello", "protocol": "HTTP/1.1", "requestId": "ee87596e-922b-4e35-9e75-47c5c1f7aa1a", "requestTime": "19/Jan/2021:14:17:10 +0000", "requestTimeEpoch": 1611065830, "resourceId": "123456", "resourcePath": "/hello", "stage": "Prod"}, "resource": "/hello", "stageVariables": null, "version": "1.0"}
2021-01-19 08:17:14,835 | Found one Lambda function with name 'HelloWorldFunction'
2021-01-19 08:17:14,835 | Invoking hello-world (go1.x)
2021-01-19 08:17:14,835 | Environment variables overrides data is standard format
2021-01-19 08:17:14,836 | Loading AWS credentials from session with profile 'None'
2021-01-19 08:17:14,859 | Resolving code path. Cwd=/Users/xxxxxxxxxxx/sam-app/.aws-sam/build, CodeUri=HelloWorldFunction
2021-01-19 08:17:14,859 | Resolved absolute path to code is /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction
2021-01-19 08:17:14,859 | Code /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction is not a zip/jar file
2021-01-19 08:17:15,985 | Failed to download image with name amazon/aws-sam-cli-emulation-image-go1.x:debug-1.15.0
2021-01-19 08:17:15,986 | Failed to download a new amazon/aws-sam-cli-emulation-image-go1.x:debug-1.15.0 image. Invoking with the already downloaded image.
2021-01-19 08:17:15,986 | Mounting /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
2021-01-19 08:17:16,388 | Setting up SIGTERM interrupt handler
2021-01-19 08:17:17,131 | Cleaning all decompressed code dirs
2021-01-19 08:17:17,131 | No response from invoke container for HelloWorldFunction
2021-01-19 08:17:17,132 | Invalid lambda response received: Lambda response must be valid json
2021-01-19 08:17:17 127.0.0.1 - - [19/Jan/2021 08:17:17] "GET /hello HTTP/1.1" 502 -
2021-01-19 08:17:17 127.0.0.1 - - [19/Jan/2021 08:17:17] "GET /favicon.ico HTTP/1.1" 403 -
2021-01-19 08:19:32,351 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "Connection": "keep-alive", "Cookie": "_xsrf=2|2b874059|3eb43ef1dfc6f978fbbc0ad98fb47dc3|1609784256; username-127-0-0-1-8888=\"2|1:0|10:1610483981|23:username-127-0-0-1-8888|44:NTRjYjg1MGQwZTFhNDE4YWI3NDY3Y2I5ZGQ2YTNiODM=|85f1aa629160bd9a7b67f2336db4a7934bcdc8ed6d2be3458bd51ac59be7a3db\"", "Host": "127.0.0.1:3000", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Encoding": ["gzip, deflate, br"], "Accept-Language": ["en-US,en;q=0.9"], "Connection": ["keep-alive"], "Cookie": ["_xsrf=2|2b874059|3eb43ef1dfc6f978fbbc0ad98fb47dc3|1609784256; username-127-0-0-1-8888=\"2|1:0|10:1610483981|23:username-127-0-0-1-8888|44:NTRjYjg1MGQwZTFhNDE4YWI3NDY3Y2I5ZGQ2YTNiODM=|85f1aa629160bd9a7b67f2336db4a7934bcdc8ed6d2be3458bd51ac59be7a3db\""], "Host": ["127.0.0.1:3000"], "Sec-Fetch-Dest": ["document"], "Sec-Fetch-Mode": ["navigate"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-User": ["?1"], "Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/hello", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "127.0.0.1:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/hello", "protocol": "HTTP/1.1", "requestId": "ee87596e-922b-4e35-9e75-47c5c1f7aa1a", "requestTime": "19/Jan/2021:14:17:10 +0000", "requestTimeEpoch": 1611065830, "resourceId": "123456", "resourcePath": "/hello", "stage": "Prod"}, "resource": "/hello", "stageVariables": null, "version": "1.0"}
2021-01-19 08:19:32,352 | Found one Lambda function with name 'HelloWorldFunction'
2021-01-19 08:19:32,352 | Invoking hello-world (go1.x)
2021-01-19 08:19:32,352 | Environment variables overrides data is standard format
2021-01-19 08:19:32,352 | Resolving code path. Cwd=/Users/xxxxxxxxxxx/sam-app/.aws-sam/build, CodeUri=HelloWorldFunction
2021-01-19 08:19:32,353 | Resolved absolute path to code is /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction
2021-01-19 08:19:32,354 | Code /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction is not a zip/jar file
2021-01-19 08:19:33,625 | Failed to download image with name amazon/aws-sam-cli-emulation-image-go1.x:debug-1.15.0
2021-01-19 08:19:33,625 | Failed to download a new amazon/aws-sam-cli-emulation-image-go1.x:debug-1.15.0 image. Invoking with the already downloaded image.
2021-01-19 08:19:33,625 | Mounting /Users/xxxxxxxxxxx/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated inside runtime container
2021-01-19 08:19:33,982 | Setting up SIGTERM interrupt handler
2021/01/19 14:19:34 Error starting mock server: fork/exec /var/rapid/init: no such file or directory
2021-01-19 08:19:34,725 | Cleaning all decompressed code dirs
2021-01-19 08:19:34,725 | No response from invoke container for HelloWorldFunction
2021-01-19 08:19:34,725 | Invalid lambda response received: Lambda response must be valid json
2021-01-19 08:19:34 127.0.0.1 - - [19/Jan/2021 08:19:34] "GET /hello HTTP/1.1" 502 -
2021-01-19 08:19:34 127.0.0.1 - - [19/Jan/2021 08:19:34] "GET /favicon.ico HTTP/1.1" 403 -

For future reference this appears to related to aws/aws-sam-cli#2462. If I install sam cli version 1.12.0 the instructions work fine.