Home

Awesome

LibreOffice Lambda Base Image

LibreOffice 7.6 base image for Lambda Node.js 20 x86_64 and Python 3.12 x86_64 to be used as a base for your own images.

Usage

Includes CJK fonts support! 877 MB in size.

Blog post announcement

Set environment variable HOME=/tmp in your Lambda function.

Node.js 20 x86_64

FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.6-node20-x86_64

COPY handler.js ${LAMBDA_TASK_ROOT}/

CMD [ "handler.handler" ]

And your handler.js:

const {execSync} = require('child_process');
const {writeFileSync} = require('fs');

module.exports.handler = () => {
  writeFileSync('/tmp/hello.txt', Buffer.from('Hello World!'));

  execSync(`
  cd /tmp
  libreoffice7.6 --headless --invisible --nodefault --view --nolockcheck --nologo --norestore --convert-to pdf --outdir /tmp ./hello.txt
  `);
};

Python 3.12 x86_64

FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.6-python3.12-x86_64

COPY handler.py ${LAMBDA_TASK_ROOT}/

CMD [ "handler.handler" ]

And your handler.py:

import subprocess

def handler(event, context):
    with open('/tmp/hello.txt', 'w') as f:
        f.write('Hello World!')

    subprocess.run([
        'libreoffice7.6',
        '--headless',
        '--invisible',
        '--nodefault',
        '--view',
        '--nolockcheck',
        '--nologo',
        '--norestore',
        '--convert-to',
        'pdf',
        '--outdir',
        '/tmp',
        '/tmp/hello.txt'
    ], check=True)

Troubleshooting

<details> <summary>Command failed: Fatal Error: The application cannot be started. User installation could not be completed. </summary>

Set environment variable HOME=/tmp in your Lambda function.

</details>

Available Tags & Versions

See Also