title: AWS SAM local with JAVA and Docker Toolbox
body: <p>I want to test my lambda functions locally with Serverless Application Model (<a href="https://aws.amazon.com/de/about-aws/whats-new/2017/08/introducing-aws-sam-local-a-cli-tool-to-test-aws-lambda-functions-locally/" rel="nofollow noreferrer">SAM</a>)
  In the AWS docs they write :</p>
  
  <blockquote>
    <p>SAM Local leverages the <strong><a href="https://hub.docker.com/r/lambci/lambda/" rel="nofollow noreferrer">docker-lambda</a></strong> Docker images to run your code in a sandbox that simulates the Lambda execution environment.</p>
  </blockquote>
  
  <p>I pulled the docker image on my computer. I could successfully run a simple Hello World Lambda Function.</p>
  
  <p><strong>Command to run Lambda function locally:</strong></p>
  
  <pre><code>$ docker run -v "$PWD/target/classes":/var/task lambci/lambda:java8 com.amazonaws.lambda.demo.LambdaFunctionHandler
  </code></pre>
  
  <p><strong>results:</strong></p>
  
  <pre><code>"Hello from Lambda!"
  </code></pre>
  
  <p><strong>Code of Lambda function automatically generated with Eclipse Toolkit:</strong>   </p>
  
  <pre><code>package com.amazonaws.lambda.demo;
  
  import com.amazonaws.services.lambda.runtime.Context;
  import com.amazonaws.services.lambda.runtime.RequestHandler;
  
  public class LambdaFunctionHandler implements RequestHandler&lt;Object, String&gt; {
  
      @Override
      public String handleRequest(Object input, Context context) {
          context.getLogger().log("Input: " + input);
  
          // TODO: implement your handler
          return "Hello from Lambda!"
      }
  
  }
  </code></pre>
  
  <p>This is my progress till yet. What i couldnt do is to use <a href="https://github.com/awslabs/aws-sam-local" rel="nofollow noreferrer">sam local</a> which uses the docker-lambda image.(Maybe i should not have to download it manually?).</p>
  
  <p>I installed sam local on my windows:</p>
  
  <pre><code>npm install -g aws-sam-local
  </code></pre>
  
  <p>created a <strong>template.yaml</strong> config sam file.</p>
  
  <pre><code>    AWSTemplateFormatVersion: 2010-09-09
  Transform: AWS::Serverless-2016-10-31
  
  Resources:
    ExampleJavaFunction:
      Type: AWS::Serverless::Function
      Properties:
        Handler: com.amazonaws.lambda.demo.LambdaFunctionHandler
        CodeUri: ./target/demo-1.0.0-shaded.jar
        Runtime: java8
  </code></pre>
  
  <p>the name for <strong>CodeUri:</strong> i choosed after i build my shaded jar file with:</p>
  
  <pre><code>mvn compile shade:shade
  </code></pre>
  
  <p>after this i should run to run my lambda function:</p>
  
  <pre><code>$ echo '{ "some": "input" }' | sam local invoke
  </code></pre>
  
  <p>NOW i have this <strong>ERROR:</strong></p>
  
  <pre><code>  2017/12/05 14:56:36 Successfully parsed template.yaml
  2017/12/05 14:56:36 Running AWS SAM projects locally requires Docker. Have you got it installed?
  2017/12/05 14:56:36 error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/_ping: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
  </code></pre>
  
  <p>What is my mistake to use SAM Local with Java? Can it be that its not working because my computer has not Hyper-V and iam using dockertoolbox?..</p>
  
  <p><a href="https://github.com/awslabs/aws-sam-local#compiled-languages-java" rel="nofollow noreferrer">here</a> you can see Advanced sam docs with compiled languages like java.</p>