aws-lambda-libreoffice 
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Inspired by chrome-aws-lambda
:information_source: 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 () => {
if (!canBeConvertedToPDF('document.docx')) {
return false;
}
return convertTo('document.docx', 'pdf');
};
Or if you want more control:
const {unpack, defaultArgs} = require('@shelf/aws-lambda-libreoffice');
await unpack();
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
License
MIT © Shelf