Skip to content

Azure

Function

TiTiler is built on top of FastAPI, a modern, fast, Python web framework for building APIs. We can make our FastAPI application work as an Azure Function by wrapping it within the Azure Function Python worker.

If you are not familiar with Azure functions we recommend checking docs.microsoft.com/en-us/azure/azure-functions/ first.

Minimal TiTiler Azure function code:

import azure.functions as func
from titiler.application.main import cog, mosaic, stac, tms
from fastapi import FastAPI


app = FastAPI()
app.include_router(cog.router, prefix="/cog", tags=["Cloud Optimized GeoTIFF"])
app.include_router(
    stac.router, prefix="/stac", tags=["SpatioTemporal Asset Catalog"]
)
app.include_router(mosaic.router, prefix="/mosaicjson", tags=["MosaicJSON"])
app.include_router(tms.router, tags=["TileMatrixSets"])


async def main(
    req: func.HttpRequest, context: func.Context,
) -> func.HttpResponse:
    return await func.AsgiMiddleware(app).handle_async(req, context)

Requirements

Deployment

See: docs.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=azure-cli%2Cbash%2Cbrowser#create-supporting-azure-resources-for-your-function

$ git clone https://github.com/developmentseed/titiler.git
$ cd titiler/deployment/azure

$ az login
$ az group create --name AzureFunctionsTiTiler-rg --location eastus
$ az storage account create --name titilerstorage --sku Standard_LRS -g AzureFunctionsTiTiler-rg
$ az functionapp create --consumption-plan-location eastus --runtime python --runtime-version 3.8 --functions-version 3 --name titiler --os-type linux -g AzureFunctionsTiTiler-rg -s titilerstorage
$ func azure functionapp publish titiler

or

use VScode: docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python#publish-the-project-to-azure

Docs