Skip to content

An AWS Lambda function that converts any document format that LibreOffice can import to any document format that LibreOffice can export

License

Notifications You must be signed in to change notification settings

javidlakha/unofunction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unofunction

An AWS Lambda function that converts any document format that LibreOffice can import to any document format that LibreOffice can export.

Deployment

Unofunction is deployed as a Lambda container image.

Please see deployment-examples for examples on how to deploy Unofunction using the AWS CDK or AWS SAM.

Dependencies

Usage

Unofunction is invoked with the following event parameters:

  • input_bucket: the bucket from which to download the file to be converted. Unofunction must have read access to this bucket
  • input_path: the path to the file to be converted in input_bucket
  • output_bucket: the bucket to upload the converted file. Unofunction must have write access to this bucket
  • output_path: the path to upload the converted file in output_bucket
  • convert_to (optional): the file format of the converted type. Must be specified if output_path does not have a file extension. If convert_to contradicts the file format inferred from output_path, convert_to takes priority

Examples

To convert a DOCX file stored at s3://unofunction-demonstration/document.docx to PDF and save the output to s3://unofunction-demonstration/document.pdf, invoke Unofunction with the following event:

{
    "input_bucket": "unofunction-demonstration",
    "input_path": "document.docx",
    "output_bucket": "unofunction-demonstration",
    "output_path": "document.pdf"
}

Where Unofunction cannot infer the desired document format from output_path, pass convert_to as an additional parameter. For example,

{
    "input_bucket": "unofunction-demonstration",
    "input_path": "document",
    "output_bucket": "unofunction-demonstration",
    "output_path": "converted-document",
    "convert_to": "docx"
}

(It is not necessary to explicitly pass the input document format, even when this cannot be inferred from input_path. LibreOffice can infer it from the document data.)

Testing

Unofunction can be tested locally or using AWS infrastructure.

To install the test dependencies set up a virtual environment and then run

pip install -r test/test-requirements.txt

Both local and AWS tests take a long time (~5 seconds per test).

Local testing

Local testing requires two further dependencies - AWS SAM and LocalStack.

To test Unofunction locally, run

sh test/test_locally.sh

Local testing does not perfectly simulate an AWS deployment. However, it does not require Unofunction to be redeployed, shortening the development cycle.

Testing on AWS infrastructure

To test Unofunction using AWS infrastructure, deploy it and input the AWS credentials of the account to which Unofunction was deployed using

aws configure

Then, run

BUCKET=$BUCKET FUNCTION=$FUNCTION pytest

where $FUNCTION is the name of Unofunction's Lambda deployment (for the examples in deployment-examples, this is 'unofunction') and $BUCKET is the name of an S3 bucket that $FUNCTION has permission to read from and write to.

Other implementations

About

An AWS Lambda function that converts any document format that LibreOffice can import to any document format that LibreOffice can export

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published