title: How to actually step by step debug in VSCode AWS Sam Local Lambda Functions
body: <p>Hey guys anyone here had success breakpointing a lambda function ran locally with visual studio code and nodejs8.10? I wonder if it's because my project is typescript.
  I've followed <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-nodejs.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-nodejs.html</a> to no avail.</p>
  
  <p>The function runs, if I do <code>stopOnEntry: true</code> vscode stops on some file, but not on my actual function's breakpoints.</p>
  
  <p>Output:</p>
  
  <pre><code>$ sam local invoke ConsumeSQSFunction --no-event --region us-west-2 -d 5858
  2019-04-30 11:19:16 Found credentials in shared credentials file: ~/.aws/credentials
  2019-04-30 11:19:16 Invoking index.processPublisherServicesQueue (nodejs8.10)
  
  Fetching lambci/lambda:nodejs8.10 Docker container image......
  2019-04-30 11:19:17 Mounting /home/dev/Documents/xxxx/main-dir/dist/lambda-section/consume-sqs as /var/task:ro,delegated inside runtime container
  Debugger listening on ws://0.0.0.0:5858/74f34edb-cdcd-4da0-82c0-950f5d809fd9
  For help see https://nodejs.org/en/docs/inspector
  Debugger attached.
  START RequestId: 1a4198ca-cceb-1b38-f251-386a239dad19 Version: $LATEST
  2019-04-30T18:19:19.800Z        1a4198ca-cceb-1b38-f251-386a239dad19    Hello World!
  2019-04-30T18:19:19.800Z        1a4198ca-cceb-1b38-f251-386a239dad19    Processing queue {} [] undefined
  END RequestId: 1a4198ca-cceb-1b38-f251-386a239dad19
  REPORT RequestId: 1a4198ca-cceb-1b38-f251-386a239dad19  Duration: 199.46 ms     Billed Duration: 200 ms Memory Size: 128 MB     Max Memory Used: 45 MB
  
  {"statusCode":200,"body":"{\"message\":\"hello world\"}"}
  Waiting for the debugger to disconnect...
  </code></pre>
  
  <p>Project structure:</p>
  
  <pre><code>launch.json
  /main-dir
     /app
          /lambda-section (where I did sam init)
                 /ConsumeSQS
                     index.ts
                template.yaml
                event.json
          /etc
     /dist
         /lambda-section
           /ConsumeSQS
              index.js
              index.js.map
  </code></pre>
  
  <p>Relevant section from template.yaml</p>
  
  <pre><code>Resources:
    ConsumeSQSFunction:
      Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
      Properties:
        FunctionName: ConsumeSQS
        Description: 'Consumes messages from SQS queue'
        CodeUri: ../../dist/lambda-section/consume-sqs/
        Handler: index.processPublisherServicesQueue
        Runtime: nodejs8.10
  </code></pre>
  
  <p>launch.json:</p>
  
  <pre><code>,
          {
              "name": "Attach to SAM CLI",
              "type": "node",
              "request": "attach",
              "address": "localhost",
              "port": 5858,
              // From the sam init example, it would be "${workspaceRoot}/hello_world"
              "localRoot": "${workspaceRoot}/main-dir/app/lambda-section",
              "remoteRoot": "/var/task",
              "protocol": "inspector",
              "stopOnEntry": false
          }
  </code></pre>