Convertapi in AWS lambda?

82 Views Asked by At

I need to deploy convertapi on an AWS Lambda.

If I try import convertapi with python, it doesn't work because I need to import it.

In AWS, we use local folder or ARN to deploy libraries.

Is there an available ARN for convertapi like in https://github.com/keithrozario/Klayers/blob/master/deployments/python3.7/arns/eu-west-3.csv ?

If not, which folder should I copy/paste in my lambda to be able to do import convertapi ?

1

There are 1 best solutions below

0
Tomas On

This is an example in Python without using ConvertAPI library.

`requests` library is required to run this example.

It can be installed using
> pip install requests

or if you are using Python 3:
> pip3 install requests
'''

import requests
import os.path
import sys

file_path = './test.docx'
secret = 'Your secret can be found at https://www.convertapi.com/a'

if not os.path.isfile(file_path):
    sys.exit('File not found: ' + file_path)

url = 'https://v2.convertapi.com/convert/docx/to/pdf?secret=' + secret
files = {'file': open(file_path, 'rb')}
headers = {'Accept': 'application/octet-stream'}

response = requests.post(url, files=files, headers=headers)

if response.status_code != 200:
    sys.exit(response.text)

output_file = open('result.pdf', 'wb') 
output_file.write(response.content)
output_file.close