We are a small, agile team of cloud experts dedicated to building secure, scalable, and innovative solutions using AWS, AI, Linux, Python, Node.js, WAF, Docker.
import boto3
from botocore.client import Config
import subprocess, os, logging, json
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
os.environ['HOME'] = '/tmp'
os.environ.setdefault('PYTHONHOME', '/usr')
os.environ.setdefault('LD_LIBRARY_PATH', '/opt/libreoffice25.2/program')
s3 = boto3.client(
's3',
region_name='us-east-1',
config=Config(signature_version='s3v4'),
endpoint_url='https://s3.us-east-1.amazonaws.com'
)
def download_file_from_s3(bucket: str, key: str, dest: str):
logger.debug("Downloading s3://%s/%s → %s", bucket, key, dest)
s3.download_file(bucket, key, dest)
def convert_pdf_to_docx(input_pdf: str, output_dir: str = '/tmp') -> str:
logger.debug("Converting PDF to DOCX: %s", input_pdf)
subprocess.run([
'libreoffice', '--headless',
'--infilter=writer_pdf_import',
'--convert-to', 'docx:MS Word 2007 XML',
'--outdir', output_dir,
input_pdf
], check=True)
base = os.path.splitext(os.path.basename(input_pdf))[0]
return os.path.join(output_dir, f"{base}.docx")
def cleanup_files(*paths):
for p in paths:
try:
if os.path.exists(p):
os.remove(p)
logger.debug("Removed %s", p)
except Exception as e:
logger.warning("Error deleting %s: %s", p, e)
def handler(event, context):
bucket = event.get('s3_bucket')
key = event.get('s3_key')
if not bucket or not key:
return {'statusCode': 400, 'body': "Missing s3_bucket or s3_key"}
pdf_name = os.path.basename(key)
local_pdf = f"/tmp/{pdf_name}"
try:
download_file_from_s3(bucket, key, local_pdf)
docx_path = convert_pdf_to_docx(local_pdf)
converted_key = f"converted-docs/{os.path.basename(docx_path)}"
s3.upload_file(docx_path, bucket, converted_key)
logger.debug("Uploaded to s3://%s/%s", bucket, converted_key)
presign = s3.generate_presigned_url(
'get_object',
Params={'Bucket': bucket, 'Key': converted_key},
ExpiresIn=3600
)
except subprocess.CalledProcessError:
logger.exception("LibreOffice conversion failed")
return {'statusCode': 500, 'body': "Conversion failed"}
except Exception as e:
logger.exception("Error in handler")
return {'statusCode': 500, 'body': f"Error: {e}"}
finally:
cleanup_files(local_pdf, locals().get('docx_path', ''))
return {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps({'download_url': presign})
}
From architecture & migration to serverless apps, container orchestration, AI/ML and security—our experts build scalable, resilient solutions tailored to your business.
Design, deploy and migrate your infrastructure to AWS for maximum reliability, performance and cost-effectiveness.
Build event-driven, auto-scaling APIs and workflows with AWS Lambda, API Gateway and Step Functions.
Containerize your workloads with Docker and run them at scale on ECS, EKS or Fargate.
Harden your stack using AWS WAF, IAM best practices, encryption and continuous monitoring.