title: How to Set Up Debugging with Dockerized SAM Local
body: <p>I'm working on a project using AWS Lambda with Node.js. We use Docker containers for our development environment.</p>
  
  <p>Our current setup spins up AWS SAM local on port :3000. It runs start-api and mounts the functions in my template.yml file. I test these functions using postman to send JSON to the mounted API endpoint like so: <a href="http://127.0.0.1:3000/foo" rel="noreferrer">http://127.0.0.1:3000/foo</a></p>
  
  <p>The Docker setup also spins up a separate Node.js instance on :4000.</p>
  
  <p>I'm able to test the Lambda stuff locally as described above. However, I want to activate debugging so that I can step through the function and inspect variables as opposed to using <code>console.log()</code>. I can't figure out how to edit the Dockerfile / docker-compose.yml to make that happen.</p>
  
  <p>Here is my docker-compose file:</p>
  
  <pre><code>version: '3'
  services:
    web:
      build: ./web
      container_name: someapp
      command: npm run dev
      volumes:
        - ./web:/usr/app/
        - /usr/app/node_modules
      ports:
        - "4000:4000"
      environment:
        DATABASE_URL: mongo://someapp:someapp@10.10.62.205:37017,10.10.62.205:37018,10.10.62.205:37019/somedb
    sam:
      build: serverless/.
      container_name: samlocal
      command: sam local start-api --host 0.0.0.0
      environment:
        COMPOSE_CONVERT_WINDOWS_PATHS: 1
        SAM_DOCKER_VOLUME_BASEDIR: ${CURRENT_DIRECTORY}/serverless
        DATABASE_URL: mongo://someapp:someapp@10.10.62.205:37017,10.10.62.205:37018,10.10.62.205:37019/somedb
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
        - ./serverless:/var/opt
      ports:
        - "3000:3000"
  </code></pre>
  
  <p>Here is the Dockerfile for SAM, which is in a directory called "serverless": </p>
  
  <pre><code>FROM alpine:3.6
  
  ENV VERSION=0.2.2
  
  RUN apk add --no-cache curl &amp;&amp; \
      curl -sSLO https://github.com/awslabs/aws-sam-local/releases/download/v${VERSION}/sam_${VERSION}_linux_386.tar.gz &amp;&amp; \
      tar -C /usr/local/bin -zxvf /sam_${VERSION}_linux_386.tar.gz &amp;&amp; \
      apk del curl &amp;&amp; \
      rm -f /sam_${VERSION}_linux_386.tar.gz
  
  # awscli for "sam package" and "sam deploy"
  RUN apk add --no-cache py-pip &amp;&amp; pip install awscli
  
  WORKDIR /var/opt
  
  EXPOSE 3000
  </code></pre>
  
  <p>I've tried various permutations of adding the --d flag to the "sam" service in RUN directive in docker-compose.yml. For example: <code>sam local start-api --host 0.0.0.0 --d 8080</code>. And then I try to change the port mapping to expose it. However, I can't figure out how to get the port mapping to work. As soon as I hit the endpoint I get port errors.</p>
  
  <p>I'm still getting up to speed on docker / docker-compose and a total nube when it comes to the Lambda stuff, so sorry if the question is silly.  </p>
  
  <p>TIA!</p>