Skip to content

Commit ac5e9c2

Browse files
authored
Add manual deployment guide for Azure Function Apps
Added a comprehensive guide for manual deployment of Azure Function Apps, including hosting options, environment variable configuration, and development steps.
1 parent 2f0e267 commit ac5e9c2

1 file changed

Lines changed: 257 additions & 0 deletions

File tree

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Function App manual deployment - Overview
2+
3+
Costa Rica
4+
5+
[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com)
6+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
7+
[brown9804](https://github.com/brown9804)
8+
9+
Last updated: 2025-09-17
10+
11+
----------
12+
13+
> [!NOTE]
14+
> Here are a few examples that demonstrate the deployment process and the creation of E2E solution. Please feel free to use them as references if needed.
15+
> - [Demo: Azure Implementation - PDF Layout Extraction with Azure AI Document Intelligence Supporting Multiple Document Versions with Visual Selection Cues (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-MultiLayout-VisualCue-AzureAI-Document-Processing)
16+
> - [Demo: Automated PDF Invoice Processing with Open Framework (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-OpenFramework)
17+
> - [Demo: PDF Layout Extraction with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Layouts-Processing-Fapp-DocIntelligence)
18+
> - [Demo: Automated PDF Invoice Processing with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-DocIntelligence)
19+
20+
## Function App Hosting Options
21+
22+
> In the context of Azure Function Apps, a `hosting option refers to the plan you choose to run your function app`. This choice affects how your function app is scaled, the resources available to each function app instance, and the support for advanced functionalities like virtual network connectivity and container support.
23+
24+
> [!TIP]
25+
>
26+
> - `Scale to Zero`: Indicates whether the service can automatically scale down to zero instances when idle.
27+
> - **IDLE** stands for:
28+
> - **I** – Inactive
29+
> - **D** – During
30+
> - **L** – Low
31+
> - **E** – Engagement
32+
> - In other words, when the application is not actively handling requests or events (it's in a low-activity or paused state).
33+
> - `Scale Behavior`: Describes how the service scales (e.g., `event-driven`, `dedicated`, or `containerized`).
34+
> - `Virtual Networking`: Whether the service supports integration with virtual networks for secure communication.
35+
> - `Dedicated Compute & Reserved Cold Start`: Availability of always-on compute to avoid cold starts and ensure low latency.
36+
> - `Max Scale Out (Instances)`: Maximum number of instances the service can scale out to.
37+
> - `Example AI Use Cases`: Real-world scenarios where each plan excels.
38+
39+
<details>
40+
<summary><strong>Flex Consumption</strong></summary>
41+
42+
| Feature | Description |
43+
|--------|-------------|
44+
| **Scale to Zero** | `Yes` |
45+
| **Scale Behavior** | `Fast event-driven` |
46+
| **Virtual Networking** | `Optional` |
47+
| **Dedicated Compute & Reserved Cold Start** | `Optional (Always Ready)` |
48+
| **Max Scale Out (Instances)** | `1000` |
49+
| **Example AI Use Cases** | `Real-time data processing` for AI models, `high-traffic AI-powered APIs`, `event-driven AI microservices`. Ideal for fraud detection, real-time recommendations, NLP, and computer vision services. |
50+
51+
</details>
52+
53+
<details>
54+
<summary><strong>Consumption</strong></summary>
55+
56+
| Feature | Description |
57+
|--------|-------------|
58+
| **Scale to Zero** | `Yes` |
59+
| **Scale Behavior** | `Event-driven` |
60+
| **Virtual Networking** | `Optional` |
61+
| **Dedicated Compute & Reserved Cold Start** | `No` |
62+
| **Max Scale Out (Instances)** | `200` |
63+
| **Example AI Use Cases** | `Lightweight AI APIs`, `scheduled AI tasks`, `low-traffic AI event processing`. Great for sentiment analysis, simple image recognition, and batch ML tasks. |
64+
65+
</details>
66+
67+
<details>
68+
<summary><strong>Functions Premium</strong></summary>
69+
70+
| Feature | Description |
71+
|--------|-------------|
72+
| **Scale to Zero** | `No` |
73+
| **Scale Behavior** | `Event-driven with premium options` |
74+
| **Virtual Networking** | `Yes` |
75+
| **Dedicated Compute & Reserved Cold Start** | `Yes` |
76+
| **Max Scale Out (Instances)** | `100` |
77+
| **Example AI Use Cases** | `Enterprise AI applications`, `low-latency AI APIs`, `VNet integration`. Ideal for secure, high-performance AI services like customer support and analytics. |
78+
79+
</details>
80+
81+
<details>
82+
<summary><strong>App Service</strong></summary>
83+
84+
| Feature | Description |
85+
|--------|-------------|
86+
| **Scale to Zero** | `No` |
87+
| **Scale Behavior** | `Dedicated VMs` |
88+
| **Virtual Networking** | `Yes` |
89+
| **Dedicated Compute & Reserved Cold Start** | `Yes` |
90+
| **Max Scale Out (Instances)** | `Varies` |
91+
| **Example AI Use Cases** | `AI-powered web applications`, `dedicated resources`. Great for chatbots, personalized content, and intensive AI inference. |
92+
93+
</details>
94+
95+
<details>
96+
<summary><strong>Container Apps Env.</strong></summary>
97+
98+
| Feature | Description |
99+
|--------|-------------|
100+
| **Scale to Zero** | `No` |
101+
| **Scale Behavior** | `Containerized microservices environment` |
102+
| **Virtual Networking** | `Yes` |
103+
| **Dedicated Compute & Reserved Cold Start** | `Yes` |
104+
| **Max Scale Out (Instances)** | `Varies` |
105+
| **Example AI Use Cases** | `AI microservices architecture`, `containerized AI workloads`, `complex AI workflows`. Ideal for orchestrating AI services like image processing, text analysis, and real-time analytics. |
106+
107+
</details>
108+
109+
## Function App: Configure/Validate the Environment variables
110+
111+
> [!NOTE]
112+
> This example is using system-assigned managed identity to assign RBACs (Role-based Access Control).
113+
114+
- Under `Settings`, go to `Environment variables`. And `+ Add` the following variables:
115+
116+
- `COSMOS_DB_ENDPOINT`: Your Cosmos DB account endpoint 🡢 `Review the existence of this, if not create it`
117+
- `COSMOS_DB_KEY`: Your Cosmos DB account key 🡢 `Review the existence of this, if not create it`
118+
- `COSMOS_DB_CONNECTION_STRING`: Your Cosmos DB connection string 🡢 `Review the existence of this, if not create it`
119+
- `invoicecontosostorage_STORAGE`: Your Storage Account connection string 🡢 `Review the existence of this, if not create it`
120+
- `FORM_RECOGNIZER_ENDPOINT`: For example: `https://<your-form-recognizer-endpoint>.cognitiveservices.azure.com/` 🡢 `Review the existence of this, if not create it`
121+
- `FORM_RECOGNIZER_KEY`: Your Documment Intelligence Key (Form Recognizer). 🡢
122+
- `FUNCTIONS_EXTENSION_VERSION`: `~4` 🡢 `Review the existence of this, if not create it`
123+
- `WEBSITE_RUN_FROM_PACKAGE`: `1` 🡢 `Review the existence of this, if not create it`
124+
- `FUNCTIONS_WORKER_RUNTIME`: `python` 🡢 `Review the existence of this, if not create it`
125+
- `FUNCTIONS_NODE_BLOCK_ON_ENTRY_POINT_ERROR`: `true` (This setting ensures that all entry point errors are visible in your application insights logs). 🡢 `Review the existence of this, if not create it`
126+
127+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/31d813e7-38ba-46ff-9e4b-d091ae02706a">
128+
129+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/45313857-b337-4231-9184-d2bb46e19267">
130+
131+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/074d2fa5-c64d-43bd-8ed7-af6da46d86a2">
132+
133+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/ec5d60f3-5136-489d-8796-474b7250865d">
134+
135+
- Click on `Apply` to save your configuration.
136+
137+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/437b44bb-7735-4d17-ae49-e211eca64887">
138+
139+
## Function App: Develop the logic
140+
141+
- You need to install [VSCode](https://code.visualstudio.com/download)
142+
- Install python from Microsoft store:
143+
144+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/30f00c27-da0d-400f-9b98-817fd3e03b1c">
145+
146+
- Open VSCode, and install some extensions: `python`, and `Azure Tools`.
147+
148+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/715449d3-1a36-4764-9b07-99421fb1c834">
149+
150+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/854aa665-dc2f-4cbf-bae2-2dc0a8ef6e46">
151+
152+
- Click on the `Azure` icon, and `sign in` into your account. Allow the extension `Azure Resources` to sign in using Microsoft, it will open a browser window. After doing so, you will be able to see your subscription and resources.
153+
154+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/4824ca1c-4959-4242-95af-ad7273c5530d">
155+
156+
- Under Workspace, click on `Create Function Project`, and choose a path in your local computer to develop your function.
157+
158+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/2c42d19e-be8b-48ef-a7e4-8a39989cea5a">
159+
160+
- Choose the language, in this case is `python`:
161+
162+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/2fb19a1e-bb2d-47e5-a56e-8dc8a708647a">
163+
164+
- Select the model version, for this example let's use `v2`:
165+
166+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/fd46ee93-d788-463d-8b28-dbf2487e9a7f">
167+
168+
- For the python interpreter, let's use the one installed via `Microsoft Store`:
169+
170+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/3605c959-fc59-461f-9e8d-01a6a92004a8">
171+
172+
- Choose a template (e.g., **Blob trigger**) and configure it to trigger on new PDF uploads in your Blob container.
173+
174+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/0a4ed541-a693-485c-b6ca-7d5fb55a61d2">
175+
176+
- Provide a function name, like `BlobTriggerContosoPDFInvoicesDocIntelligence`:
177+
178+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/263cef5c-4460-46cb-8899-fb609b191d81">
179+
180+
- Next, it will prompt you for the path of the blob container where you expect the function to be triggered after a file is uploaded. In this case is `pdfinvoices` as was previously created.
181+
182+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/7005dc44-ffe2-442b-8373-554b229b3042">
183+
184+
- Click on `Create new local app settings`, and then choose your subscription.
185+
186+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/07c211d6-eda0-442b-b428-cdaed2bf12ac">
187+
188+
- Choose `Azure Storage Account for remote storage`, and select one. I'll be using the `invoicecontosostorage`.
189+
190+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/3b5865fc-3e84-4582-8f06-cb5675d393f0">
191+
192+
- Then click on `Open in the current window`. You will see something like this:
193+
194+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/f30e8e10-0c37-4efc-8158-c83faf22a7d8">
195+
196+
- Now we need to update the function code to extract data from PDFs and store it in Cosmos DB, use this an example:
197+
198+
> 1. **PDF Upload**: A PDF file is uploaded to the Azure Blob Storage container (`pdfinvoices`).
199+
> 2. **Trigger Azure Function**: The upload triggers the Azure Function `BlobTriggerContosoPDFLayoutsDocIntelligence`.
200+
> 3. **Initialize Clients**: Sets up connections to Azure Document Intelligence and Cosmos DB.
201+
> - Initializes the `DocumentAnalysisClient` using the `FORM_RECOGNIZER_ENDPOINT` and `FORM_RECOGNIZER_KEY` environment variables.
202+
> - Initializes the `CosmosClient` using Azure Active Directory (AAD) via `DefaultAzureCredential`.
203+
> 4. **Read PDF from Blob Storage**: Reads the PDF content from the blob into a byte stream.
204+
> 5. **Analyze PDF**: Uses Azure Document Intelligence to analyze the layout of the PDF.
205+
> - Calls `begin_analyze_document` with the `prebuilt-layout` model.
206+
> - Waits for the analysis to complete and retrieves the layout result.
207+
> 6. **Extract Layout Data**: Parses and structures the layout data from the analysis result.
208+
> - Extracts lines, tables, and selection marks from each page.
209+
> - Logs styles (e.g., handwritten content) and organizes data into a structured dictionary.
210+
> 7. **Save Data to Cosmos DB**: Saves the structured layout data to Cosmos DB.
211+
> - Ensures the database (`ContosoDBDocIntellig`) and container (`Layouts`) exist or creates them.
212+
> - Inserts or updates the layout data using `upsert_item`.
213+
> 8. **Logging (Process and Errors)**: Logs each step of the process, including success messages and detailed error handling for debugging and monitoring.
214+
215+
- Update the function_app.py, for example see the code used in each demo:
216+
- [Demo: Azure Implementation - PDF Layout Extraction with Azure AI Document Intelligence Supporting Multiple Document Versions with Visual Selection Cues (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-MultiLayout-VisualCue-AzureAI-Document-Processing)
217+
- [Demo: Automated PDF Invoice Processing with Open Framework (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-OpenFramework)
218+
- [Demo: PDF Layout Extraction with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Layouts-Processing-Fapp-DocIntelligence)
219+
- [Demo: Automated PDF Invoice Processing with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-DocIntelligence)
220+
221+
| Template Blob Trigger | Function Code updated |
222+
| --- | --- |
223+
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/07a7b285-eed2-4b42-bb1f-e41e8eafd273"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/d364591b-817e-4f36-8c50-7de187c32a1e">|
224+
225+
- Now, let's update the `requirements.txt`, see the code used in each demo:
226+
- [Demo: Azure Implementation - PDF Layout Extraction with Azure AI Document Intelligence Supporting Multiple Document Versions with Visual Selection Cues (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-MultiLayout-VisualCue-AzureAI-Document-Processing)
227+
- [Demo: Automated PDF Invoice Processing with Open Framework (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-OpenFramework)
228+
- [Demo: PDF Layout Extraction with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Layouts-Processing-Fapp-DocIntelligence)
229+
- [Demo: Automated PDF Invoice Processing with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-DocIntelligence)
230+
231+
| Template `requirements.txt` | Updated `requirements.txt` |
232+
| --- | --- |
233+
| <img width="550" alt="image" src="https://github.com/user-attachments/assets/239516e0-a4b7-4e38-8c2b-9be12ebb00de"> | <img width="550" alt="image" src="https://github.com/user-attachments/assets/91bd6bd8-ec21-4e1a-ae86-df577d37bcbb">|
234+
235+
- Since this function has already been tested, you can deploy your code to the function app in your subscription. If you want to test, you can use run your function locally for testing.
236+
- Click on the `Azure` icon.
237+
- Under `workspace`, click on the `Function App` icon.
238+
- Click on `Deploy to Azure`.
239+
240+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/12405c04-fa43-4f09-817d-f6879fbff035">
241+
242+
- Select your `subscription`, your `function app`, and accept the prompt to overwrite:
243+
244+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/b69212a5-ab79-45e2-8344-73198b231d07">
245+
246+
- After completing, you see the status in your terminal:
247+
248+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/6214e246-5beb-4ae4-a54b-9101cac3e241">
249+
250+
<img width="550" alt="image" src="https://github.com/user-attachments/assets/78aab42c-af43-43aa-a4c0-545f4445755b">
251+
252+
> [!IMPORTANT]
253+
> If you need a hand with the code, just check out some of the examples, they’ve got extra information.
254+
> - [Demo: Azure Implementation - PDF Layout Extraction with Azure AI Document Intelligence Supporting Multiple Document Versions with Visual Selection Cues (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-MultiLayout-VisualCue-AzureAI-Document-Processing)
255+
> - [Demo: Automated PDF Invoice Processing with Open Framework (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-OpenFramework)
256+
> - [Demo: PDF Layout Extraction with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Layouts-Processing-Fapp-DocIntelligence)
257+
> - [Demo: Automated PDF Invoice Processing with Doc Intelligence (full-code approach)](https://github.com/MicrosoftCloudEssentials-LearningHub/PDFs-Invoice-Processing-Fapp-DocIntelligence)

0 commit comments

Comments
 (0)