# Azure Function for Metadata

Decube can leverage a customer-hosted Azure Function to retrieve file schemas, minimizing file egress from the customer's environment to Decube's compute. While this approach is generally applicable to the SaaS deployment model, it can also be beneficial for self-hosted solutions where the Data Plane resides in a different region than the Storage Container.

## Prerequisite

* Create an Azure Function with Custom Handler as the Runtime Stack
* Networking between Decube Data Plane (either SaaS or customer own) to the Azure Function

## Creating Azure Function

1. Go to your Azure Portal and navigate to Function App and click on \`Create\`

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-a8b4e9d6e8cfec8832020c6128b962a71b08583c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

2. Choose either Consumption (recommended), Functions Premium or App Service

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-c057f42b7e07e2a15a7e36d66d030bcc07a552cf%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Fill in the appropriate field
   1. Function App Name - a unique name for this function
   2. Runtime stack - Custom Handler
   3. Region - Closest to your ADLS storage account region
   4. Operating System - Linux

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-6c62a700833ebe3f02714e43a4f6712adce9af5d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

4. Under Networking, choose Enable Public Access - On
   1. See [Azure documentation](https://learn.microsoft.com/en-us/azure/azure-functions/functions-networking-options?tabs=azure-portal) if alternate networking is required

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-3d7ba39f006fd97602f2228524f2b06b26894e41%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

5. Under Deployment, disable Continous Deployment
6. Storage, Monitoring, Tags are to be set up according to customer need
7. Create the Azure Function

## Deployment

Visit <https://github.com/DecubeIO/adls-azure-function> to start

1. Clone the repo to a local machine
2. Run `func azure functionapp publish $functionAppName --custom`
   1. `$functionAppName`is based on the Azure Function name used in [#creating-azure-function](#creating-azure-function "mention")

## Using the Azure Function

<figure><img src="https://1779874722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTw0qpCVzfrIXqS4FEg4T%2Fuploads%2Fgit-blob-3bbf9be05c1eaf2c22fb63ae9c51bea6c77bb35a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

1. When creating/modifying an ADLS source, enable `Use remote Azure Function`
2. Fill in the Azure Function URL in this format: `https://myfunction.azurewebsites.net`
3. Fill in the Azure Function Key. This can be found in your Portal Azure > Go to created function above > Functions > App Keys > Either choose an existing host key or create a new host key
