TiTiler is built on top of FastAPI, a modern, fast, Python web framework for building APIs. As for AWS Lambda we can make our FastAPI application work on Azure Function by wrapping it within the Azure Function Python worker.
If you are not familiar with Azure functions we recommend checking https://docs.microsoft.com/en-us/azure/azure-functions/ first.
Minimal TiTiler Azure function code:
import azure.functions as func
from titiler.application.routers 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"])
def main(
req: func.HttpRequest, context: func.Context,
) -> func.HttpResponse:
return func.AsgiMiddleware(app).handle(req, context)
Note: there is a bug
in azure.functions.AsgiMiddleware
which prevent using starlette.BaseHTTPMiddleware
middlewares (see: Azure/azure-functions-python-worker#903).
- Azure CLI: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
- Azure Function Tool: https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
$ 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
$ az functionapp create --consumption-plan-location eastus --runtime python --runtime-version 3.8 --functions-version 3 --name titiler --os-type linux
$ func azure functionapp publish titiler
or