• Stars
    star
    512
  • Rank 86,323 (Top 2 %)
  • Language
    Dockerfile
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run LibreOffice in AWS Lambda to create PDFs & convert documents

Serverless LibreOffice

UPD 2022-06

See libreoffice-lambda-base-image & aws-lambda-libreoffice for the latest updates

πŸ‘‰πŸ» Read the blog post on Medium: How to Run LibreOffice in AWS Lambda for Dirty-Cheap PDFs atΒ Scale πŸ‘ˆπŸ»

Show Me the Code

This repo contains code used to run the online demo.

β”œβ”€β”€ compile.sh  <-- commands used to compile LibreOffice for Lambda
β”œβ”€β”€ infra       <-- terraform config to deploy example Lambda
β”‚Β Β  β”œβ”€β”€ iam.tf
β”‚Β Β  β”œβ”€β”€ lambda.tf
β”‚Β Β  β”œβ”€β”€ main.tf
β”‚Β Β  β”œβ”€β”€ s3.tf
β”‚Β Β  └── vars.tf
└── src         <-- example Lambda function node in Node.js used for website demo
    β”œβ”€β”€ handler.js
    β”œβ”€β”€ libreoffice.js
    β”œβ”€β”€ logic.js
    β”œβ”€β”€ package.json <-- put lo.tar.gz in this folder to deploy. Download it below
    └── s3.js

Compiled and ready to use archive can be downloaded under Releases section. Also check out NPM package with bundled LibreOffice for Lambda (85 MB).

✨ Check out a new Lambda Layer with LibreOffice!

How to compile by yourself

Check out a comprehensive step-by-step tutorial from 0 to deployed function.

To run this, you will need to Docker and docker-compose installed.

  1. Install and configure Docker and docker-compose locally or on a c5.2xlarge spot instance with ~ 8 GB (the default) of storage attached.
  2. In a terminal, run docker-compose run --rm libreoffice. It will compile LibreOffice and then copy layers.zip to your local drive.

Help

Related Projects

How To Help

Reduce Cold Start Time

Currently Ζ› unpacks 109 MB .tar.gz to /tmp folder which takes ~1-2 seconds on cold start.

Would be nice to create a single compressed executable to save unpack time and increase portability. I tried using Ermine packager and it works!! But unfortunately this is commercial software. Similar open-source analogue Statifier produces broken binaries.

Maybe someone has another idea how to create a single executable from a folder full of shared objects.

UPD: TODO: Check out node-packer and libsquash (no FUSE required!)

Further Size Reduction

I am not a Linux or C++ expert, so for sure I missed some easy "hacks" to reduce size of compiled LibreOffice.

Mostly I just excluded from compilation as much unrelated stuff as possible. And stripped symbols from shared objects.

Here is the list of: available RPM packages and libraries available in AWS Lambda Environment, which can be helpful.

You can also use multi compression level, with upx and then decompress after brotli.

Testing

Update repo for testing. Return before S3 for example, hardcode or generate files to convert and setup variables. Then simply run:

docker run \
 -v "\$PWD":/var/task \
 lambci/lambda:nodejs12.x src/handler.handler

After successful execution, get the resulted files to check the pdfs.

docker ps -a

Find exect container id.

Then execute

docker cp containerId:/tmp/filename.pdf ./filename.pdf

Then check your results locally

License

MIT Β© Vlad Holubiev

More Repositories

1

docker-in-aws-lambda

Run Docker containers in AWS Lambda
Shell
85
star
2

quickreview-for-github

Reviewing 50+ Pull Requests a day is no fun. Automate it with keyboard shortcuts.
TypeScript
68
star
3

docker-graphviz-png-cli

CLI to render *.dot -> *.png
Dockerfile
33
star
4

docker-libreoffice-pdf-cli

Convert any doc to pdf without installing LibreOffice and its dependencies
Dockerfile
25
star
5

gh-shipit

Automate GitHub releases, PRs, labels, release notes
TypeScript
19
star
6

lambda-custom-authorizer-middleware

Lambda Custom Authorizer Middleware for using with AWS Serverless Express and Serverless Offline plugins
JavaScript
8
star
7

kadira

Original Kadira with tweaks to run in Docker
JavaScript
6
star
8

GMMEnhancer

The most feature-rich Google Map Maker Chrome Extension!
JavaScript
5
star
9

aws-xray-trace-id

Get AWS X-Ray Trace Id from Lambda Environment
JavaScript
3
star
10

mongo-move

Move docs between MongoDB collection, matching criterias, and w/ optional transformer
TypeScript
2
star
11

awsnews.info

Source code of https://awsnews.info/
TypeScript
2
star
12

simple-ecs-restart-cli

Simply Restart Service: for local development, red/green, without creating a new task definition
JavaScript
2
star
13

11klas-homework

HTML
2
star
14

aws-news-post-formatter

Formats & fixes HTML from AWS News API; Extracts custom tags based on the headline
TypeScript
2
star
15

s3-bucket-name-validator

Validate S3 bucket name and get error reason
JavaScript
2
star
16

discovervenues

Test task: Browse through interesting places on a map and export them to .csv
CoffeeScript
1
star
17

gmm-users-finder

Scan stream of last edits to find active Google Map Maker users
Java
1
star
18

gmm-approval

Meteor App to automate manual edits approval in Google Map Maker
CoffeeScript
1
star
19

aws-news-api-client

AWS News API Client with retry behavior
TypeScript
1
star
20

gmm-parser

Grab, parse and analyze history of user edits to generate monthly leaderboards for Google Map Maker
Java
1
star
21

pretty-version-diff

Print semver version diff like sindresorhus/np CLI
JavaScript
1
star
22

mongo-projection-from-keys

Generate MongoDB projection from list of keys to include / exclude
JavaScript
1
star
23

vkCommonality

Find out mainstream trends among your friends!
Java
1
star
24

concurrency-checker

For educational purposes. Lambda Concurrency @ Scale
HCL
1
star
25

vladholubiev.com

Personal website
JavaScript
1
star