title: AWS Lambda function with ImageMagick layer on Nodejs10.x
body: <p>I have been trying to create a Lambda function that uses the ImageMagick CLI to convert high resolution images to offload my server. I have deployed the <a href="https://github.com/serverlesspub/imagemagick-aws-lambda-2" rel="nofollow noreferrer">imagemagick-aws-lambda-2</a> and extracted the layer and added it to my function, but I have not been successful in calling the imagemagick CLI. Everything I try just gets a "Error: Command failed: convert: No such file or directory".</p>
  
  <p>I have tried other layers, I have tried downloading the layers and adding them manually to the function, I have tried setting the PATH variables in different ways, but still haven't been able to get it to work. When deploying it to Lambda I can see my layer has been embedded properly in my function. At this point I would just like to get the most basic use case to work with the "convert" command.</p>
  
  <p>My template.yaml:</p>
  
  <pre><code>Transform: AWS::Serverless-2016-10-31
  Description: &gt;
    wpPoster
  
    Sample SAM Template for wpPoster
  
  Globals:
    Function:
      Timeout: 60
  
  Resources:
    TestPosterFunction:
      Type: AWS::Serverless::Function
      Properties:
        FunctionName: TestPoster
        Description: Test of TestPoster function
        CodeUri: test-poster/
        Handler: index.lambdaHandler
        Runtime: nodejs10.x
        Layers:
          - arn:aws:lambda:eu-west-1:xxxxxxxxxxxxx:layer:image-magick:1
  </code></pre>
  
  <p>My index.js:</p>
  
  <pre><code>const exec = require('child_process').exec;
  
  exports.lambdaHandler = function(event, context, callback) {
      exec('convert -version', function(error, stdout, stderr) {
          if (error) {
              console.log(error);
          }
          console.log(stdout);
      });
  
      callback();
  };
  </code></pre>
  
  <p>I'm using VS Studio Code with AWS SAM for coding and testing locally, which should download and cache any external layer.</p>