Giter VIP home page Giter VIP logo

aws-lambda-libreoffice's Introduction

aws-lambda-libreoffice

85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli

Inspired by chrome-aws-lambda

ℹ️ Compiled LibreOffice version: 6.4.0.1

Install

$ yarn add @shelf/aws-lambda-libreoffice

NOTE: Since version 2.0.0 npm package no longer ships the 85 MB LibreOffice but relies upon libreoffice-lambda-layer instead. Follow the instructions on how to add a lambda layer in that repo.

Usage

const {convertTo, canBeConvertedToPDF} = require('@shelf/aws-lambda-libreoffice');

module.exports.handler = async () => {
  // assuming there is a document.docx file inside /tmp dir
  // original file will be deleted afterwards

  if (!canBeConvertedToPDF('document.docx')) {
    return false;
  }

  return convertTo('document.docx', 'pdf'); // returns /tmp/document.pdf
};

Or if you want more control:

const {unpack, defaultArgs} = require('@shelf/aws-lambda-libreoffice');

await unpack(); // default path /tmp/instdir/program/soffice.bin

execSync(
  `/tmp/instdir/program/soffice.bin ${defaultArgs.join(
    ' '
  )} --convert-to pdf file.docx --outdir /tmp`
);

Troubleshooting

  • Please allocate at least 1536 MB of RAM for your Lambda function.
  • It works only in Amazon Linux 2, so it won't work locally on Linux or macOS. However, you could run it in Docker using lambci/lambda:nodejs12.x image
  • If some file fails to be converted to PDF, try converting it to PDF on your computer first. This might be an issue with LibreOffice itself

See Also

Test

Smoke test that it works: ./test.sh. Make sure to clone libreoffice-lambda-layer repo alongside

Publish

$ git checkout master
$ yarn version
$ yarn publish
$ git push origin master

License

MIT © Shelf

aws-lambda-libreoffice's People

Contributors

renovate-bot avatar vladholubiev avatar vladgolubev avatar randomhash avatar dependabot[bot] avatar diidiiman avatar knupman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.