TOKIUM / poppler-aws-lambda-layer

Poppler on AWS Lambda
GNU General Public License v2.0
1 stars 0 forks source link

Usage example or issue with layer? #5

Open pratiksyngenta opened 3 years ago

pratiksyngenta commented 3 years ago
'use strict';
const { spawnSync } = require('child_process');
const commandExistsSync = require('command-exists').sync;

module.exports.hello = async (event) => {
  console.log('Im in function hello !!!');
  if (commandExistsSync('ls')) {
    console.log('LS- yes');
  } else {
    console.log('LS- no');
  }
  if (commandExistsSync('/opt/bin/htmltopdf')) {
    console.log('html- yes');
  } else {
    console.log('html- no');
  }

  const process = spawnSync('/opt/bin/pdfinfo -v', [], {
    stdio: 'inherit',
    stderr: 'inherit'
  });
  console.log(process);
  console.log(JSON.stringify(process));

  return {
    statusCode: 200,
    body: JSON.stringify({
      hi: 'Say Hi'
    }),
  };
};

log says: image

homuler commented 3 years ago

Will you share the steps to reproduce the error?

/opt/bin is set to PATH by default (see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime), so if you deployed this layer and configured your lambda function to use it, you can call pdfinfo -v.

Here is a real-world example, though it's not documented in English. https://github.com/BEARTAIL/thumbnail-generator-lambda/blob/main/src/services/pdf-service.ts#L52-L71