import os os.environ["PATH"] += ":/opt/python/pandoc" import boto3 import pandoc # must be after adding path otherwise pandoc will not be found. S3_BUCKET = os.environ["S3_BUCKET"] def lambda_handler(event, context): s3 = boto3.client("s3") filename = "feature_evaluation_report_v1.1" tmp_doc = "/tmp/sss.docx" if event.get("kwargs") is not None: filename = event["kwargs"]["filename"] with open("/tmp/a.html", "wb") as f: s3.download_fileobj(S3_BUCKET, f"html/{filename}.html", f) # s3.download_fileobj(S3_BUCKET, 'html/sales_report_na.html', f) a = pandoc.read(file="/tmp/a.html", format="html") pandoc.write(a, file=tmp_doc, format="docx") s3.upload_file(tmp_doc, S3_BUCKET, f"docx/{filename}.docx") # s3.upload_file(tmp_doc, S3_BUCKET, 'docx/sales_report_na.docx')