aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Golang lambda can't hit breakpoints in VSCode #1310

Closed ghost closed 4 years ago

ghost commented 5 years ago

Description

When I attempt to debug a sample golang lambda via delve and vscode using sam local start-api -d 5987 --debugger-path ./debugger --debug-args="-delveAPI=2" --debug, I cannot hit my breakpoints or pause the debugger, however delve does halt and wait for input;

I can hit breakpoints in goland.

Steps to reproduce

Setup

Setup commands /batch script

if exist sam-app RMDIR /S /Q sam-app
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)

sam init  --runtime go1.x

cd sam-app
go get -u github.com/go-delve/delve/cmd/dlv
go get -u github.com/aws/aws-lambda-go/...
setx GOARCH amd64
setx GOOS linux
set GOARCH=amd64
set GOOS=linux
mkdir debugger
go env
go build  -gcflags "all=-N -l" -o ./debugger/dlv github.com/go-delve/delve/cmd/dlv
go build  -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world
mkdir .vscode
copy ../launch.json .vscode/launch.json
start code .
sam local start-api -d 5987 --debugger-path ./debugger --debug-args="-delveAPI=2"

My launch.json file in the same folder as the batch script is

{
    "version": "0.2.0",
    "configurations": [

    {
        "name": "Connect to Lambda container",
        "type": "go",
        "request": "attach",
        "mode": "remote",
        "remotePath": "/var/task/hello-world",
        "port": 5987,
        "host": "127.0.0.1",
        "trace" : "verbose"
      },
    ]
}

Observed result

2019-08-01 17:06:16 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-08-01 17:06:16 Changing event name from before-call.apigateway to before-call.api-gateway
2019-08-01 17:06:16 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-08-01 17:06:16 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-08-01 17:06:16 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-08-01 17:06:16 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-08-01 17:06:16 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-08-01 17:06:16 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-08-01 17:06:16 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-08-01 17:06:16 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-08-01 17:06:16 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-08-01 17:06:16 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-08-01 17:06:16 Changing event name from before-call.apigateway to before-call.api-gateway
2019-08-01 17:06:16 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-08-01 17:06:16 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-08-01 17:06:16 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-08-01 17:06:16 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-08-01 17:06:16 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-08-01 17:06:16 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-08-01 17:06:16 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-08-01 17:06:16 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-08-01 17:06:16 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-08-01 17:06:16 local start-api command is called
2019-08-01 17:06:16 No Parameters detected in the template
2019-08-01 17:06:16 2 resources found in the template
2019-08-01 17:06:16 Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
2019-08-01 17:06:16 Trying paths: ['C:\\Users\\james.walker\\.docker\\config.json', 'C:\\Users\\james.walker\\.dockercfg']
2019-08-01 17:06:16 Found file at path: C:\Users\james.walker\.docker\config.json
2019-08-01 17:06:16 Found 'auths' section
2019-08-01 17:06:16 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-08-01 17:06:16 Found 'credsStore' section
2019-08-01 17:06:16 http://localhost:None "GET /v1.35/_ping HTTP/1.1" 200 2
2019-08-01 17:06:16 No Parameters detected in the template
2019-08-01 17:06:16 2 resources found in the template
2019-08-01 17:06:16 Found '1' API Events in Serverless function with name 'HelloWorldFunction'
2019-08-01 17:06:16 Detected Inline Swagger definition
2019-08-01 17:06:16 Lambda function integration not found in Swagger document at path='/hello' method='get'
2019-08-01 17:06:16 Found '0' APIs in resource 'ServerlessRestApi'
2019-08-01 17:06:16 Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2019-08-01 17:06:16 1 APIs found in the template
2019-08-01 17:06:16 Trying paths: ['C:\\Users\\james.walker\\.docker\\config.json', 'C:\\Users\\james.walker\\.dockercfg']
2019-08-01 17:06:16 Found file at path: C:\Users\james.walker\.docker\config.json
2019-08-01 17:06:16 Found 'auths' section
2019-08-01 17:06:16 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-08-01 17:06:16 Found 'credsStore' section
2019-08-01 17:06:16 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2019-08-01 17:06:16 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
2019-08-01 17:06:16 Localhost server is starting up. Multi-threading = False
2019-08-01 17:06:16  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2019-08-01 17:09:48 Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/hello", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/hello", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "Prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/hello"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "PostmanRuntime/7.15.2", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "449f463f-74d7-438d-b6de-12f80ccf205e", "Host": "127.0.0.1:3000", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"User-Agent": ["PostmanRuntime/7.15.2"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["449f463f-74d7-438d-b6de-12f80ccf205e"], "Host": ["127.0.0.1:3000"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/hello", "isBase64Encoded": false}
2019-08-01 17:09:48 Found one Lambda function with name 'HelloWorldFunction'
2019-08-01 17:09:48 Invoking hello-world (go1.x)
2019-08-01 17:09:48 Environment variables overrides data is standard format
2019-08-01 17:09:48 Loading AWS credentials from session with profile 'None'
2019-08-01 17:09:48 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-08-01 17:09:48 Changing event name from before-call.apigateway to before-call.api-gateway
2019-08-01 17:09:48 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-08-01 17:09:48 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-08-01 17:09:48 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-08-01 17:09:48 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-08-01 17:09:48 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-08-01 17:09:48 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-08-01 17:09:48 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-08-01 17:09:48 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-08-01 17:09:48 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-08-01 17:09:48 Looking for credentials via: env
2019-08-01 17:09:48 Found credentials in environment variables.
2019-08-01 17:09:48 Resolving code path. Cwd=H:\Branches\Git\newAttempt\sam-app, CodeUri=hello-world/
2019-08-01 17:09:48 Resolved absolute path to code is H:\Branches\Git\newAttempt\sam-app\hello-world
2019-08-01 17:09:48 Code H:\Branches\Git\newAttempt\sam-app\hello-world is not a zip/jar file
2019-08-01 17:09:48 Skipping building an image since no layers were defined
2019-08-01 17:09:48 Trying paths: ['C:\\Users\\james.walker\\.docker\\config.json', 'C:\\Users\\james.walker\\.dockercfg']
2019-08-01 17:09:48 Found file at path: C:\Users\james.walker\.docker\config.json
2019-08-01 17:09:48 Found 'auths' section
2019-08-01 17:09:48 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-08-01 17:09:48 Found 'credsStore' section
2019-08-01 17:09:48 http://localhost:None "GET /v1.35/images/lambci/lambda:go1.x/json HTTP/1.1" 200 None
2019-08-01 17:09:48 Looking for auth config
2019-08-01 17:09:48 Using credentials store "wincred"
2019-08-01 17:09:48 Looking for auth entry for 'https://index.docker.io/v1/'
2019-08-01 17:09:48 Found auth config
2019-08-01 17:09:50 http://localhost:None "POST /v1.35/images/create?tag=go1.x&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:go1.x Docker container image......
2019-08-01 17:09:50 Mounting H:\Branches\Git\newAttempt\sam-app\hello-world as /var/task:ro,delegated inside runtime container
2019-08-01 17:09:51 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2019-08-01 17:09:51 http://localhost:None "GET /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/json HTTP/1.1" 200 None
2019-08-01 17:09:51 http://localhost:None "GET /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/json HTTP/1.1" 200 None
2019-08-01 17:09:51 http://localhost:None "POST /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/start HTTP/1.1" 204 0
2019-08-01 17:09:51 Setting up SIGTERM interrupt handler
2019-08-01 17:09:51 http://localhost:None "GET /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/json HTTP/1.1" 200 None
2019-08-01 17:09:51 http://localhost:None "POST /containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5987
2019-08-01T16:09:52Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-08-01T16:10:54Z debug layer=debugger continuing
START RequestId: 0d1142b0-06b7-113f-918a-ff7595fc264f Version: $LATEST
END RequestId: 0d1142b0-06b7-113f-918a-ff7595fc264f
REPORT RequestId: 0d1142b0-06b7-113f-918a-ff7595fc264f     Duration: 541.98 ms     Billed Duration: 600 ms Memory Size: 128 MB     Max Memory Used: 29 MB  
2019-08-01 17:10:56 http://localhost:None "GET /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9/json HTTP/1.1" 200 None
2019-08-01 17:10:56 http://localhost:None "DELETE /v1.35/containers/ea10b1f332d2131b200a5f67a58fbdf9e4a613e054b5673614f93c27baa617f9?v=False&link=False&force=True HTTP/1.1" 204 0
2019-08-01 17:10:56 No Content-Type given. Defaulting to 'application/json'.
2019-08-01 17:10:56 127.0.0.1 - - [01/Aug/2019 17:10:56] "GET /hello HTTP/1.1" 200 -
2019-08-01 17:11:13 Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/hello", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/hello", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "Prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/hello"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "PostmanRuntime/7.15.2", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "2670b0eb-8d73-4104-b68c-495a3863f887", "Host": "127.0.0.1:3000", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"User-Agent": ["PostmanRuntime/7.15.2"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["2670b0eb-8d73-4104-b68c-495a3863f887"], "Host": ["127.0.0.1:3000"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/hello", "isBase64Encoded": false}
2019-08-01 17:11:13 Found one Lambda function with name 'HelloWorldFunction'
2019-08-01 17:11:13 Invoking hello-world (go1.x)
2019-08-01 17:11:13 Environment variables overrides data is standard format
2019-08-01 17:11:13 Loading AWS credentials from session with profile 'None'
2019-08-01 17:11:13 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-08-01 17:11:13 Changing event name from before-call.apigateway to before-call.api-gateway
2019-08-01 17:11:13 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-08-01 17:11:13 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-08-01 17:11:13 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-08-01 17:11:13 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-08-01 17:11:13 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-08-01 17:11:13 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-08-01 17:11:13 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-08-01 17:11:13 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-08-01 17:11:13 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-08-01 17:11:13 Looking for credentials via: env
2019-08-01 17:11:13 Found credentials in environment variables.
2019-08-01 17:11:13 Resolving code path. Cwd=H:\Branches\Git\newAttempt\sam-app, CodeUri=hello-world/
2019-08-01 17:11:13 Resolved absolute path to code is H:\Branches\Git\newAttempt\sam-app\hello-world
2019-08-01 17:11:13 Code H:\Branches\Git\newAttempt\sam-app\hello-world is not a zip/jar file
2019-08-01 17:11:13 Skipping building an image since no layers were defined
2019-08-01 17:11:13 Trying paths: ['C:\\Users\\james.walker\\.docker\\config.json', 'C:\\Users\\james.walker\\.dockercfg']
2019-08-01 17:11:13 Found file at path: C:\Users\james.walker\.docker\config.json
2019-08-01 17:11:13 Found 'auths' section
2019-08-01 17:11:13 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-08-01 17:11:13 Found 'credsStore' section
2019-08-01 17:11:13 http://localhost:None "GET /v1.35/images/lambci/lambda:go1.x/json HTTP/1.1" 200 None
2019-08-01 17:11:13 Looking for auth config
2019-08-01 17:11:13 Using credentials store "wincred"
2019-08-01 17:11:13 Looking for auth entry for 'https://index.docker.io/v1/'
2019-08-01 17:11:13 Found auth config
2019-08-01 17:11:14 http://localhost:None "POST /v1.35/images/create?tag=go1.x&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:go1.x Docker container image......
2019-08-01 17:11:14 Mounting H:\Branches\Git\newAttempt\sam-app\hello-world as /var/task:ro,delegated inside runtime container
2019-08-01 17:11:14 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2019-08-01 17:11:14 http://localhost:None "GET /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/json HTTP/1.1" 200 None
2019-08-01 17:11:14 http://localhost:None "GET /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/json HTTP/1.1" 200 None
2019-08-01 17:11:15 http://localhost:None "POST /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/start HTTP/1.1" 204 0
2019-08-01 17:11:15 Setting up SIGTERM interrupt handler
2019-08-01 17:11:15 http://localhost:None "GET /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/json HTTP/1.1" 200 None
2019-08-01 17:11:15 http://localhost:None "POST /containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5987
2019-08-01T16:11:15Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-08-01 17:13:40 Ctrl+C was pressed. Aborting Lambda execution
2019-08-01 17:13:40 http://localhost:None "GET /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277/json HTTP/1.1" 200 None
2019-08-01 17:13:40 http://localhost:None "DELETE /v1.35/containers/0095de3221c026cc5b870ef2495b7e9d73cfdb7395f4166c6dbbbb0f55a8f277?v=False&link=False&force=True HTTP/1.1" 204 0
2019-08-01 17:13:40 Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object). Response received:
2019-08-01 17:13:40 127.0.0.1 - - [01/Aug/2019 17:13:40] "GET /hello HTTP/1.1" 502 -
2019-08-01 17:13:56 Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/hello", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/hello", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "Prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/hello"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "PostmanRuntime/7.15.2", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "80193429-34bf-4e0d-8d0e-0f461d1e754a", "Host": "127.0.0.1:3000", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"User-Agent": ["PostmanRuntime/7.15.2"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["80193429-34bf-4e0d-8d0e-0f461d1e754a"], "Host": ["127.0.0.1:3000"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/hello", "isBase64Encoded": false}
2019-08-01 17:13:56 Found one Lambda function with name 'HelloWorldFunction'
2019-08-01 17:13:56 Invoking hello-world (go1.x)
2019-08-01 17:13:56 Environment variables overrides data is standard format
2019-08-01 17:13:56 Loading AWS credentials from session with profile 'None'
2019-08-01 17:13:56 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-08-01 17:13:56 Changing event name from before-call.apigateway to before-call.api-gateway
2019-08-01 17:13:56 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-08-01 17:13:56 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-08-01 17:13:56 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-08-01 17:13:56 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-08-01 17:13:56 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-08-01 17:13:56 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-08-01 17:13:56 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-08-01 17:13:56 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-08-01 17:13:56 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-08-01 17:13:56 Looking for credentials via: env
2019-08-01 17:13:56 Found credentials in environment variables.
2019-08-01 17:13:56 Resolving code path. Cwd=H:\Branches\Git\newAttempt\sam-app, CodeUri=hello-world/
2019-08-01 17:13:56 Resolved absolute path to code is H:\Branches\Git\newAttempt\sam-app\hello-world
2019-08-01 17:13:56 Code H:\Branches\Git\newAttempt\sam-app\hello-world is not a zip/jar file
2019-08-01 17:13:56 Skipping building an image since no layers were defined
2019-08-01 17:13:56 Trying paths: ['C:\\Users\\james.walker\\.docker\\config.json', 'C:\\Users\\james.walker\\.dockercfg']
2019-08-01 17:13:56 Found file at path: C:\Users\james.walker\.docker\config.json
2019-08-01 17:13:56 Found 'auths' section
2019-08-01 17:13:56 Auth data for https://index.docker.io/v1/ is absent. Client might be using a credentials store instead.
2019-08-01 17:13:56 Found 'credsStore' section
2019-08-01 17:13:56 http://localhost:None "GET /v1.35/images/lambci/lambda:go1.x/json HTTP/1.1" 200 None
2019-08-01 17:13:56 Looking for auth config
2019-08-01 17:13:56 Using credentials store "wincred"
2019-08-01 17:13:56 Looking for auth entry for 'https://index.docker.io/v1/'
2019-08-01 17:13:56 Found auth config
2019-08-01 17:13:57 http://localhost:None "POST /v1.35/images/create?tag=go1.x&fromImage=lambci%2Flambda HTTP/1.1" 200 None

Fetching lambci/lambda:go1.x Docker container image......
2019-08-01 17:13:57 Mounting H:\Branches\Git\newAttempt\sam-app\hello-world as /var/task:ro,delegated inside runtime container
2019-08-01 17:13:58 http://localhost:None "POST /v1.35/containers/create HTTP/1.1" 201 90
2019-08-01 17:13:58 http://localhost:None "GET /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/json HTTP/1.1" 200 None
2019-08-01 17:13:58 http://localhost:None "GET /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/json HTTP/1.1" 200 None
2019-08-01 17:13:58 http://localhost:None "POST /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/start HTTP/1.1" 204 0
2019-08-01 17:13:58 Setting up SIGTERM interrupt handler
2019-08-01 17:13:58 http://localhost:None "GET /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/json HTTP/1.1" 200 None
2019-08-01 17:13:58 http://localhost:None "POST /containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/attach?stdout=1&stderr=1&logs=1&stream=1&stdin=0 HTTP/1.1" 101 0
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5987
2019-08-01T16:13:58Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-08-01T16:14:17Z debug layer=debugger continuing
START RequestId: d137b0cb-5326-11a4-ca28-3ecde6c3a539 Version: $LATEST
END RequestId: d137b0cb-5326-11a4-ca28-3ecde6c3a539
REPORT RequestId: d137b0cb-5326-11a4-ca28-3ecde6c3a539     Duration: 452.54 ms     Billed Duration: 500 ms Memory Size: 128 MB     Max Memory Used: 27 MB  
2019-08-01 17:14:18 http://localhost:None "GET /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f/json HTTP/1.1" 200 None
2019-08-01 17:14:18 http://localhost:None "DELETE /v1.35/containers/debb808975f8b0d11430067741267ad460f40039964b379a0dea9bca082f8c7f?v=False&link=False&force=True HTTP/1.1" 204 0
2019-08-01 17:14:18 No Content-Type given. Defaulting to 'application/json'.
2019-08-01 17:14:18 127.0.0.1 - - [01/Aug/2019 17:14:18] "GET /hello HTTP/1.1" 200 -

Expected result

Debugging to work with breakpoints.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows
  2. sam --version: 0.18.0

Add --debug flag to command you are running

ghost commented 5 years ago

I have also left a comment here in case it is an issue with vs-code go: https://github.com/microsoft/vscode-go/issues/2010#issuecomment-517326186

awood45 commented 5 years ago

This is something we want to support, but I don't think at this point we officially support breakpoint debugging in Go. It is promising to see that goland step-through debugging is working, so will keep this open for reference.

Related: https://github.com/aws/aws-toolkit-jetbrains/issues/649

jackmcguire1 commented 5 years ago

perhaps try debugging commands specified in https://github.com/Microsoft/vscode-go/issues/1555

For now, i would recommend not running delveAPI=2 with your debug command as it will default back to version 1, which VS code can support by specifying this within settings.json for vs code { "go.delveConfig": { "apiVersion":1 } }

for reference https://github.com/awslabs/aws-sam-cli/issues/886

ghost commented 5 years ago

perhaps try debugging commands specified in microsoft/vscode-go#1555

For now, i would recommend not running delveAPI=2 with your debug command as it will default back to version 1, which VS code can support by specifying this within settings.json for vs code { "go.delveConfig": { "apiVersion":1 } }

for reference #886

Unfortunately I tried API version one, and still couldn't set the breakpoint, attached is my debug logs - seems it can't find the file when setting the breakpoint even though it exists on disk vscode-go-debug.txt

jackmcguire1 commented 5 years ago

Ok i have just debugged my API endpoint using VScode to debug with APi-Version 2, however, I have rectified the launch.json.

Could it be your template / handler configuration? you have said it works within Goland, so I don't see this being the issue, perhaps the folder which visual studio code has opened?

  1. I start the aws sam start-api function,
  2. it displays all available API endpoints ,i .e. 'http://127.0.0.1:3000/test'
  3. Go to 'http://127.0.0.1:3000/test' on web browser
  4. AWS SAM CLI continues to fetch/init docker container
  5. VS CODE start debugging

{ "version": "0.2.0", "configurations": [ { "name": "Connect to Lambda container", "type": "go", "request": "attach", "mode": "remote", "remotePath": "", "port": 5986, "host": "127.0.0.1" }, ] }

Screen Shot 2019-08-20 at 16 43 07

ghost commented 5 years ago

I tried your launch.json but unfortunately I'm still getting

SetBreakPointsRequest
All cleared
Creating on: H:\Branches\Git\newAttempt\sam-app\hello-world\main.go:25
Creating on: H:\Branches\Git\newAttempt\sam-app\hello-world\main.go:26
Creating on: H:\Branches\Git\newAttempt\sam-app\hello-world\main.go:30
Error on CreateBreakpoint: could not find file H:\Branches\Git\newAttempt\sam-app\hello-world\main.go
Error on CreateBreakpoint: could not find file H:\Branches\Git\newAttempt\sam-app\hello-world\main.go
Error on CreateBreakpoint: could not find file H:\Branches\Git\newAttempt\sam-app\hello-world\main.go
All set:[null,null,null]
jackmcguire1 commented 5 years ago

this feels like a vscode issue in regards to file location, you're running the file from a separate drive by the looks of it... which could be an issue? could you copy your code on to your c:/ drive and also paste your template.yaml file

jackmcguire1 commented 5 years ago

see https://github.com/Microsoft/vscode-go/issues/2318 aswell

ghost commented 5 years ago

I've just copied it to C:\ and get the same error message below but for the C:\ drive - my template.yaml is just the one generated by sam init --runtime go1.x, but I'll attach it anyway added txt onto the ending to upload it to github.

template.yaml.txt

[14:53:45.337 UTC] To client: {"seq":0,"type":"response","request_seq":2,"command":"launch","success":true}
[14:53:45.340 UTC] From client: setBreakpoints({"source":{"name":"main.go","path":"h:\\Branches\\Git\\newAttempt\\sam-app\\hello-world\\main.go"},"lines":[25],"breakpoints":[{"line":25}],"sourceModified":false})
[14:53:45.340 UTC] SetBreakPointsRequest
[14:53:45.340 UTC] All cleared
[14:53:45.341 UTC] Creating on: H:\Branches\Git\newAttempt\sam-app\hello-world\main.go:25
[14:53:45.345 UTC] Error on CreateBreakpoint: could not find file H:\Branches\Git\newAttempt\sam-app\hello-world\main.go
[14:53:45.345 UTC] All set:[null]
[14:53:45.347 UTC] To client: {"seq":0,"type":"response","request_seq":3,"command":"setBreakpoints","success":true,"body":{"breakpoints":[{"verified":false,"line":25}]}}
[14:53:45.347 UTC] SetBreakPointsResponse
[14:53:45.362 UTC] From client: setExceptionBreakpoints({"filters":[]})
[14:53:45.362 UTC] To client: {"seq":0,"type":"response","request_seq":4,"command":"setExceptionBreakpoints","success":true}
[14:53:45.366 UTC] From client: configurationDone(undefined)
[14:53:45.367 UTC] ConfigurationDoneRequest
[14:53:45.368 UTC] ContinueRequest
[14:53:45.368 UTC] To client: {"seq":0,"type":"response","request_seq":5,"command":"configurationDone","success":true}
[14:53:45.368 UTC] ContinueResponse
[14:53:45.374 UTC] From client: threads(undefined)
[14:53:45.375 UTC] To client: {"seq":0,"type":"response","request_seq":6,"command":"threads","success":true,"body":{"threads":[{"id":1,"name":"Dummy"}]}}
ghost commented 5 years ago

Whoops sorry - I copied from the wrong vscode-debug.txt - here is the right one

[16:10:30.861 UTC] To client: {"seq":0,"type":"response","request_seq":2,"command":"attach","success":true}
[16:10:30.867 UTC] From client: setBreakpoints({"source":{"name":"main.go","path":"c:\\Users\\james.walker\\source\\repos\\newAttempt\\sam-app\\hello-world\\main.go"},"lines":[25,26,30],"breakpoints":[{"line":25},{"line":26},{"line":30}],"sourceModified":false})
[16:10:30.868 UTC] SetBreakPointsRequest
[16:10:30.868 UTC] All cleared
[16:10:30.868 UTC] Creating on: C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go:25
[16:10:30.869 UTC] Creating on: C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go:26
[16:10:30.869 UTC] Creating on: C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go:30
[16:10:30.872 UTC] Error on CreateBreakpoint: could not find file C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go
[16:10:30.873 UTC] Error on CreateBreakpoint: could not find file C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go
[16:10:30.873 UTC] Error on CreateBreakpoint: could not find file C:\Users\james.walker\source\repos\newAttempt\sam-app\hello-world\main.go
[16:10:30.873 UTC] All set:[null,null,null]
[16:10:30.873 UTC] To client: {"seq":0,"type":"response","request_seq":3,"command":"setBreakpoints","success":true,"body":{"breakpoints":[{"verified":false,"line":25},{"verified":false,"line":26},{"verified":false,"line":30}]}}
[16:10:30.874 UTC] SetBreakPointsResponse
[16:10:31.058 UTC] From client: setExceptionBreakpoints({"filters":[]})
[16:10:31.058 UTC] To client: {"seq":0,"type":"response","request_seq":4,"command":"setExceptionBreakpoints","success":true}
[16:10:31.093 UTC] From client: configurationDone(undefined)
[16:10:31.094 UTC] ConfigurationDoneRequest
[16:10:31.094 UTC] ContinueRequest
[16:10:31.094 UTC] To client: {"seq":0,"type":"response","request_seq":5,"command":"configurationDone","success":true}
[16:10:31.094 UTC] ContinueResponse
[16:10:31.103 UTC] From client: threads(undefined)
[16:10:31.103 UTC] To client: {"seq":0,"type":"response","request_seq":6,"command":"threads","success":true,"body":{"threads":[{"id":1,"name":"Dummy"}]}}

Also I tried changing handler to main - but it just result in a command line error when invoking the lambda. could not launch process: fork/exec /var/task/main: no such file or directory

jackmcguire1 commented 5 years ago

Yes apologies the template modification is wrong, this issue is definitely a windows / vscode issue I’m afraid, as it’s workjng fine for goland.

KarthickEmis commented 5 years ago

@jackmcguire1 i tried the same in visual studio code for go lang .. I am getting the below error

{ "errorMessage": "fork/exec /tmp/lambci_debug_files/dlv: exec format error", "errorType": "PathError" }?[0m 2019-08-27 17:42:43 Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object).

Note:

set GOARCH=amd64 set GOOS=linux mkdir debugger go build -gcflags "all=-N -l" -o ./debugger/dlv github.com/go-delve/delve/cmd/dlv go build -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world sam local start-api -d 5987 --debugger-path ./debugger --debug-args="-delveAPI=2"

PFA my template.yaml file and launch.json file. template.txt

{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "attach", "mode": "remote", "remotePath": "", "port": 5988, "host": "127.0.0.1" // "program": "${fileDirname}", // "env": {}, // "args": [] } ] }

whether i need to run dlv in my container and need to point out in build command ? If so kindly give some example.

KarthickEmis commented 5 years ago

I just tried the below steps sam init --runtime go1.x cd sam-app code . # to launch VSCode go get -u github.com/go-delve/delve/cmd/dlv GOARCH=amd64 GOOS=linux go build -o ./dlv github.com/go-delve/delve/cmd/dlv go get -u github.com/aws/aws-lambda-go/... GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o hello-world/hello-world ./hello-world sam local start-api -d 5986 --debugger-path . --debug-args="-delveAPI=2"

debugger is not attaching in VS code .. but code is running

KarthickEmis commented 5 years ago

@jackmcguire1 , could you specify the version of your GoLang , VS Code , CLI used?

jackmcguire1 commented 5 years ago

Your debug port in vs code settings in wrong!! It should be 5986 or whatever you set in ‘sam local start-api -d 5986’

Hi karth, according to your error, your hello world lambda is not returning a correct Response observe the hello world code and make sure it is returning api gateway response with the body being set @KarthickEmis

I was incorrect about having main in template, keep it to hello world!!!

jackmcguire1 commented 5 years ago

I hope this helps ^^

KarthickEmis commented 5 years ago

Your debug port in vs code settings in wrong!! It should be 5986 or whatever you set in ‘sam local start-api -d 5986’ Hi karth, according to your error, your hello world lambda is not returning a correct Response observe the hello world code and make sure it is returning api gateway response with the body being set @KarthickEmis I was incorrect about having main in template, keep it to hello world!!!

@jackmcquire1 , I tried with new simple go lang program

sam init --runtime go1.x cd sam-app code . # to launch VSCode go get -u github.com/go-delve/delve/cmd/dlv set GOARCH=amd64 set GOOS=linux go build -o ./dlv github.com/go-delve/delve/cmd/dlv go get -u github.com/aws/aws-lambda-go/... set GOARCH=amd64 set GOOS=linux go build -gcflags="-N -l" -o hello-world/main ./hello-world sam local start-api -d 5989 --debugger-path . --debug-args="-delveAPI=2"

debugger is not attaching in VS code .. but code is working( value is returning in browser)

When i try to run the below command , sam local start-api -d 5989 --debugger-path . --debug-args="-delveAPI=2" , i can see upto the below lines in terminal 2019-08-28 10:42:16 Mounting C:\go-work\src\sam-app1\sam-app\hello-world as /var/task:ro,delegated inside runtime container Could not create config directory: mkdir .config: read-only file system.API server listening at: [::]:5989 2019-08-28T05:12:17Z info layer=debugger launching process with args: [/var/task/main],

It get strucked after this .once I restart the debugger in VS code , I am getting value in browser and getting logs in terminal but not hitting break point.

2019-08-28T05:12:57Z debug layer=debugger continuing ?[32mSTART RequestId: 959e2982-4823-1ac4-38a2-db2fb097b6d0 Version: $LATEST?[0m ?[32mEND RequestId: 959e2982-4823-1ac4-38a2-db2fb097b6d0?[0m ?[32mREPORT RequestId: 959e2982-4823-1ac4-38a2-db2fb097b6d0 Duration: 1178.29 ms Billed Duration: 1200 ms Memory Size: 128 MB Max Memory Used: 30 MB ?[0m 2019-08-28 10:42:59 No Content-Type given. Defaulting to 'application/json'. 2019-08-28 10:42:59 127.0.0.1 - - [28/Aug/2019 10:42:59] "GET /hello HTTP/1.1" 200 - 2019-08-28 10:42:59 127.0.0.1 - - [28/Aug/2019 10:42:59] "GET /favicon.ico HTTP/1.1" 403

Note: I tried -delveAPI=1 also , but not working versions in my system : VsCode: 1.37.1 aws-cli - 1.16.26 aws sam cli 0.19.0 Docker For Windows: 19.03.1

template.txt

My launch.json { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Connect to Lambda container", "type": "go", "request": "attach", "mode": "remote", "remotePath": "/var/task/main", "port": 5989, "host": "127.0.0.1" // "program": "${workspaceRoot}", // "env": {}, // "args": [] } ] }

Kindly let me know whether delve has to run in container , if so provide me the steps to run.

jackmcguire1 commented 5 years ago

You can see in logs that debugger is continuing, so dlv is definitely running perhaps , not sure why vscode is not detecting / enforcing the break point, make sure go extension in vscode is upto date, etc.

We could schedule to talk on discord or team viewer, I think you’re close to getting this working

KarthickEmis commented 5 years ago

You can see in logs that debugger is continuing, so dlv is definitely running perhaps , not sure why vscode is not detecting / enforcing the break point, make sure go extension in vscode is upto date, etc. We could schedule to talk on discord or team viewer, I think you’re close to getting this working

@jackmcguire1 , I am using the latest version of vs code ( version 1.37.1). Kindly let me know your availability time , so that we can join through team viewer or skype

ghost commented 4 years ago

@jackmcguire1 I've been investigating this further including why VSCode does not debug and Goland down and it seems to be down to the fact that VSCode sends delve JSON-RPC commands specifying the location of the file and the line to breakpoint, and Goland sends the memory address to breakpoint at. For the former,when debugging remotely, Delve requires access to a copy of the source code so it knows where to set the breakpoint.

However in AWS SAM, the Delve debugger, and the binary to be debuggged is run inside a temporary docker container, so Delve cannot locate the source file, fails to set the breakpoint, and the program completes.

I tried to fix this by waiting until AWS SAM / delve halted for a debugger to attach, and then copying the source files into the docker instance via the AWS SAM file share, and using vscodes remotePath: to pick it up, but unfortunately Delve did not pick up the files.

This might be solved by having AWS SAM mount the source code, and pointing Delve towards these files so vscode can work.

I have also commented on issue the go extension for visual studio code - https://github.com/microsoft/vscode-go/issues/2010

However this might be more easily resolved on the AWS SAM end by mounting source code

ghost commented 4 years ago

@KarthickEmis @jackmcguire1 After further investigation into the Delve debugger , I've discovered the following:

  1. The compiler go build encodes filepaths and lines in the following format: 1.a. Windows Subsystem for linux with GOOS=linux : /c/git/linux/exampleFile/main.go 1.b. Windows with GOOS=linux : C:/Git/exampleFile/main.go
  2. The binary is then zipped up ready for deployment
  3. AWS SAM is then started via a command on the lines of sam local start-api -t api-gateway.yml -d 5987 --debugger-path ./api/bin --debug-args="-debug -delveAPI=2"
  4. A call is made to SAM local which then mounts both the executable and the delve debugger
  5. The delve debugger is started and then immediately halts due it's headless commands waiting for a remote debugger to attached, it listens on port 5987
  6. VSCode opened in the project directory, and it's launch.json contains something on the lines of
    {
    "type": "go",
    "name": "Connect to Lambda container",
    "request": "attach",
    "mode": "remote",
    "remotePath": "/c/git/linux/exampleFile"
    "port": 5987,
    "host": "127.0.0.1",
    "showLog": true,
    "trace": "log"
    }
  7. A breakpoint is added in exampleFile/main.go
  8. VSCode is attached to the remote debugger
  9. VSCode examines the breakpointed files and joins them to the remotePath in the launch.json e.g. '/c/git/linux/exampleFile' + '/main.go'
  10. This is then passed to delve which compares the full file path against the one compiled into the executable - if it exists then the breakpoint is set there
  11. Debugging is continued until it hits the breakpoint

Breakpoints fail when the compiled path is different then the composite path of remotePath, and the relative path to the file for the VSCode - it is not needed for source code on the remote machine, as this line info is built into the binary.

Where my code was failing was because I built in WSL linux, but my vscode remote path did not have a linux style path to my code directory.

Unfortunately, if I choose the option of compiling in Windows with GOOS=linux, then the paths compiled into the binary look like: Unfortunately, if I choose the option of compiling in Windows with GOOS=linux, then the paths compiled into the binary look like:

The nature of the slashes are different, and so the breakpoints are not hit. This would require either a change to Go build to change the compiled files on a window system with GOOS=linux, or more easily, to change VSCode so it send paths inP OSIX format when remote connecting to a linux machine. A third option is for delve to rewrite paths passed in so they are in POSIX format