Aspose-words cannot deployed in Azure Function

I am using the Aspose.Words Python library to perform the following tasks:

  • Convert DOCX files to PDF
  • Split DOCX documents
  • Merge multiple DOCX documents into one

The Azure Function App works perfectly in my local environment without any issues. However, when I deploy it to Azure, it fails to deploy correctly.

I am using Ubuntu 22.04 with Python 3.11. Does the Aspose.Words Python library not support Linux-based Azure Functions?

I have already purchased an OEM license. Please help me resolve this issue.

@sachithaPDF

To successfully deploy the Aspose.Words Python library in an Azure Function on a Linux environment, there are specific requirements that need to be addressed. While the library works well locally, deployment issues can arise due to missing dependencies or configurations.

Here are some steps you can take to resolve the issue:

  1. Check Dependencies: Ensure that all necessary dependencies are included in your deployment. For Aspose.Words to function correctly on Linux, you may need to install additional packages. For example, fontconfig is often required for rendering fonts properly.

  2. Docker Configuration: If you are using Docker for your Azure Function, you can create a Dockerfile that includes the necessary installations. Here’s a sample Dockerfile that you can adapt:

    FROM public.ecr.aws/lambda/python:3.8
    RUN yum install -y fontconfig
    COPY app.py ${LAMBDA_TASK_ROOT}
    COPY requirements.txt .
    RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
    CMD ["app.handler"]
    

    This Dockerfile installs fontconfig, copies your application code, and installs the required Python packages.

  3. Testing: Before deploying to Azure, test your function locally using Docker to ensure that it behaves as expected. This can help identify any issues before deployment.

  4. Azure Function Configuration: Make sure that your Azure Function is configured correctly to use the appropriate runtime and that it matches the environment you tested locally.

If you continue to experience issues, consider checking the Azure Function logs for any error messages that could provide more insight into what might be going wrong during deployment.

For more detailed information, you may want to refer to the official Aspose documentation regarding Linux support and any specific configurations required for Azure Functions.

If you have any further questions or need additional assistance, feel free to ask!

@sachithaPDF Could you please elaborate the problem you have encountered? Does Aspose.Words throw any exceptions? Thee should not be any problems with using Aspose.Words for Python in Ubuntu. Here you can find list of Dockerfiles we tested Aspose.Words with:
https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET/blob/master/Dockerfile

This is the only exception I can see in the " Availability and Performance" option. Here is the pipeline.yaml that i am using…

trigger:
  branches:
    include:
      - "main"
  paths:
    exclude:
      - 'azure-pipelines.yml'

pr: none

stages:  
- stage: Build  
  jobs:  
  - job: Build
    pool:
      vmImage: 'ubuntu-latest'  
    steps:  

    - task: UsePythonVersion@0
      inputs:
        versionSpec: '3.11.x'
        addToPath: true
        architecture: 'x64'

    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
        pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt  

    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)/'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- stage: Deploy_Dev
  dependsOn: Build
  condition: succeeded()  
  jobs:
  - deployment: Deploy_Dev
    environment: 'DEV' 
    pool:
      name: 'Name LNX SH Pool'  
    strategy:
      runOnce:
        deploy:  
          steps: 
 
          - task: DownloadBuildArtifacts@1
            inputs:
              buildType: 'current'
              downloadType: 'single'
              downloadPath: '$(System.ArtifactsDirectory)'
              cleanDestinationFolder: true

          - task: AzureFunctionApp@2
            inputs:
              connectedServiceNameARM: 'Name_ARM_MI_DEV'
              appType: 'functionAppLinux'
              appName: 'functionappname'
              package: '$(System.ArtifactsDirectory)/**/*.zip'
              runtimeStack: 'PYTHON|3.11'
              deploymentMethod: 'auto'              

@sachithaPDF Thank you for additional information. But unfortunately, it does not give any clue what is going wrong. Also, there is nothing about Aspose.Words.

The above exception is the only error that occurs during deployment. To test the deployment, I commented out the line import aspose.words as aw and all code related to Aspose. After doing this, the deployment succeeded.

Next, I uncommented the import aspose.words line and redeployed the changes. However, the deployment failed again. This confirms that the issue is with the Aspose.Words library import. Do we need to use docker in az function? Cant we use the library directly in az function without using docker

@sachithaPDF Thank you for additional information. I will consult with my colleagues and get back to you soon.

1 Like

Thank you for the update. Additionally, could you provide instructions on how to run the Azure Durable Function in Docker? What additional commands do I need to include in the following Dockerfile? I need to call the Durable Function via an HTTP request. The URL is:
http://localhost:7071/api/orchestrators/rfp_orchestrator?content_id=XXXX4&client_name=XXXX
To run the az durable function locally, I used following command : func host start --port 7071

This is the folder structure :

# Start image ubuntu_22.04_py311
FROM ubuntu:22.04
RUN apt update && apt install -y python3.11
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections
RUN apt install -y ttf-mscorefonts-installer
RUN apt install -y python3-pip
RUN apt install -y wget
RUN python3.11 -m pip install pillow
RUN python3.11 -m pip install --upgrade pip
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
RUN update-alternatives --auto python3
RUN wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
RUN dpkg -i ./libssl1.1_1.1.0g-2ubuntu4_amd64.deb
RUN rm -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb

@sachithaPDF
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSPYTHON-60

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Additionally, could you provide instructions on how to run the Azure Durable Function in Docker?

unfortunately, I am not an Azure expert. Here is what ChatGPT suggests:

Running an Azure Durable Function in a Docker container involves the following steps:


1. Install Prerequisites

Ensure the following are installed on your machine:


2. Create an Azure Durable Function

If you don’t already have a Durable Function, create one:

  • Use the Azure Functions Core Tools:
func init MyDurableFunctionApp --docker
cd MyDurableFunctionApp
func new --template "Durable Functions Orchestration" --name MyDurableFunction

3. Add a Dockerfile

If you selected the --docker option during project initialization, a Dockerfile will already be present. If not, create a Dockerfile based on your runtime. Below is an example for Python and Node.js:

For Python:

FROM mcr.microsoft.com/azure-functions/python:4-python3.10

COPY . /home/site/wwwroot
RUN pip install --no-cache-dir -r /home/site/wwwroot/requirements.txt

For Node.js:

FROM mcr.microsoft.com/azure-functions/node:4-node18

COPY . /home/site/wwwroot

For .NET:

FROM mcr.microsoft.com/azure-functions/dotnet:4

COPY . /home/site/wwwroot

4. Build and Run Locally with Docker

  1. Build the Docker image:
docker build -t my-durable-function .
  1. Run the Docker container:
docker run -p 8080:80 my-durable-function
  1. Access the function at http://localhost:8080.

5. Configure for Durable Functions

Durable Functions require a storage account for their state management. For local development:

  1. Set the AzureWebJobsStorage environment variable in the Docker container to point to an Azure Storage Emulator (like Azurite) or a real Azure Storage Account.Example local.settings.json file:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python"
  }
}
  1. Copy this configuration into your Docker container by adding:
ENV AzureWebJobsStorage="UseDevelopmentStorage=true"
ENV FUNCTIONS_WORKER_RUNTIME="python"

6. Push the Image to a Container Registry

Push the image to a container registry like Azure Container Registry or Docker Hub:

docker tag my-durable-function <registry-name>/<image-name>
docker push <registry-name>/<image-name>

7. Deploy to Azure

  1. Create an Azure Function App configured for Docker containers:
az functionapp create --name MyFunctionApp \
  --storage-account <storage_account_name> \
  --resource-group <resource_group_name> \
  --plan <app_service_plan_name> \
  --deployment-container-image-name <registry-name>/<image-name>
  1. Configure the app with necessary environment variables (AzureWebJobsStorage, etc.) using the Azure portal or CLI.

Thank you for your support! I successfully ran it using Docker. However, I am still awaiting a fix for the initial issue regarding the direct use of the Aspose.Words Python library in an Azure Function (Linux-based, running on Ubuntu).

@sachithaPDF We will investigate the issue and let you know once the issue is resolved or we have more information for you.

1 Like