An Azure service that provides an event-driven serverless compute platform.
Hello Mohamed,
Thank you for reaching out to the Microsoft Q&A community.
The issue you are encountering is due to the fact that your PDF generation code relies on specific OS-level Linux libraries (such as cairo, pango, etc.), which are not included in the default environment for the Flex Consumption plan.
Unfortunately, you cannot install these system libraries or use a custom container on the Flex Consumption plan. As per the official Microsoft documentation, Flex Consumption operates in a sandboxed environment without root access and only supports code deployments.
Quoting the Deployment technologies in Azure Functions documentation:
"One deploy is the only deployment technology available for function apps running in a Flex Consumption plan... When you create a Flex Consumption app, you must specify a deployment storage (blob) container... The end result is a ready-to-run .zip package."
Additionally, the Functions infrastructure as code documentation explicitly confirms that the Flex Consumption plan is restricted to "Code-only", whereas plans like Premium and Dedicated support both "Code | Container".
Resolution:
To resolve the missing dependencies, you will need to migrate your function to a hosting plan that supports Custom Containers. This gives you full root control over the underlying OS to install necessary Linux packages. You can choose one of the following alternatives:
- Azure Functions Premium Plan or Dedicated (App Service) Plan
- Azure Container Apps (ACA)
Here is how you can resolve it using an Azure Functions Premium Plan:
- Create a Custom Dockerfile: Build a custom container based on the official Azure Functions base image and install your OS-level dependencies.
FROM mcr.microsoft.com/azure-functions/python:4-python3.11 # Install necessary Linux packages for PDF generation RUN apt-get update && \ apt-get install -y libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 shared-mime-info && \ apt-get clean && rm -rf /var/lib/apt/lists/* COPY . /home/site/wwwroot - Push the Image: Build and push this Docker image to a registry such as Azure Container Registry (ACR).
- Deploy to Premium Plan: Create a new Azure Function App, choose Container as the Publish option, select the Premium pricing plan, and configure it to pull your custom image.
Please let me know if you need any further clarification on migrating your plan.
Note: This response is drafted with the help of AI system.