Skip to content

Conversation

@zpg6
Copy link
Owner

@zpg6 zpg6 commented Nov 4, 2025

Adds ability to configure a database, cache, or other relevant Azure service as "bound" to your function.

1) Declare in your azure.config.json below your other app configuration

{
    "bindings": {
        "DB": {
            "type": "cosmos-sql",
            "databaseName": "mydb",
            "throughput": 400
        },
        "CACHE": {
            "type": "redis",
            "sku": "Basic",
            "capacity": 0
        }
    }
}

2) Easy typesafe access to your bindings (CosmosClient, ServiceBusClient, etc)

// app/api/users/route.ts
import { getBinding } from "opennextjs-azure/bindings";

export async function GET() {
    const db = getBinding<"cosmos-sql">("DB");

    const database = db.database("mydb");
    const container = database.container("users");
    const { resources } = await container.items.readAll().fetchAll();

    return Response.json(resources);
}

Environment variables "bound" to the function app are handled with the others in the bicep, as well as provisioning the resources in the app's resource group. Bicep file is programmatically modified at deploy-time with these added specifics.

@zpg6 zpg6 self-assigned this Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants