Vercel Integration with Azure Cosmos DB

APPLIES TO: NoSQL MongoDB

Vercel offers a user-friendly and robust platform for web application development and deployment. This new integration improves productivity as developers can now easily create Vercel applications with a backend database already configured. This Integration helps developers transform their creative ideas into reality in real-time.

Getting started with Integrating Azure Cosmos DB with Vercel

This documentation is designed for developers seeking to effectively combine the robust capabilities of Azure Cosmos DB - a globally distributed, multi-model database service - with Vercel's high-performance deployment and hosting solution.

This integration enables developers to apply the benefits of a versatile and high-performance NoSQL database, while capitalizing on Vercel's serverless architecture and development platform.

There are two ways to integrate Azure Cosmos DB.

Integrate Cosmos DB with Vercel via Integration Marketplace

Use this guide if you have already identified the Vercel projects or want to integrate an existing vercel project with

Prerequisites

Steps for Integrating Azure Cosmos DB with Vercel

  1. Select Vercel Projects for the Integration with Azure Cosmos DB. After you have the prerequisites ready, visit the Cosmos DB integrations page on the Vercel marketplace and select Add Integration

    Screenshot shows the Azure Cosmos DB integration page on Vercel's marketplace.

  2. Choose All projects or Specific projects for the integration. In this guide we proceed by choosing specific projects. Select Install to continue.

    Screenshot shows to select vercel projects.

  3. Sign in to your existing Microsoft account, or if you don’t have one, create a new account as depicted in next step.

    Screenshot shows to log in to Azure account.

  4. Click on 'create one' to create a new Microsoft account.

Note

Microsoft account is different from an Azure Cosmos DB account. We will be creating an Azure Cosmos DB account in following steps

Screenshot shows to create new Microsoft Account.

  1. If you want to use an existing Azure Cosmos DB account, choose the existing Directory, subscription and the Azure Cosmos DB Account(Skip to step 9) . To create a new Azure Try Cosmos DB account, click on 'Create new account'.

    Screenshot shows to create new Azure Try Cosmos DB Account.

  2. Select API type (currently only NOSQL and MongoDB API are supported) and click on 'Create Account'.

    Screenshot shows to select the type of API of the Azure Cosmos DB account.

  3. After the successful Try Azure Cosmos DB account creation, click on 'Continue'

Screenshot shows to continue with the integration.

  1. Click on 'Accept' in the pop-up to access the Try Azure Cosmos DB account. (Mandatory to complete the Integration).

    Screenshot shows to accept the access.

  2. Select Integrate and you're done.

    Screenshot shows to confirm the integration.

Integrate Cosmos DB with Vercel via npm & Command Line

  1. Execute create-next-app with npm, yarn, or pnpm to bootstrap the example:

    npx create-next-app --example with-azure-cosmos with-azure-cosmos-app
    
    yarn create next-app --example with-azure-cosmos with-azure-cosmos-app
    
    pnpm create next-app --example with-azure-cosmos with-azure-cosmos-app
    
  2. Modify pages/index.tsx to add your code.

    Make changes to pages/index.tsx according to your needs. You could check out the code at lib/cosmosdb.ts to see how the @azure/cosmos JavaScript client is initialized.

  3. Push the changes to a GitHub repository.

Set up environment variables

  • COSMOSDB_CONNECTION_STRING - You need your Cosmos DB connection string. You can find these in the Azure portal in the keys section.

  • COSMOSDB_DATABASE_NAME - Name of the database you plan to use. This should already exist in the Azure Cosmos DB account.

  • COSMOSDB_CONTAINER_NAME - Name of the container you plan to use. This should already exist in the previous database.

Integrate Cosmos DB with Vercel using marketplace template

We have an Azure Cosmos DB Next.js Starter, which a great ready-to-use template with guided structure and configuration, saving you time and effort in setting up the initial project setup. Click on Deploy to Deploy on Vercel and View Repo to view the source code.

  1. Choose the GitHub repository, where you want to clone the starter repo. Screenshot to create the repository.

  2. Select the integration to set up Cosmos DB connection keys, these steps are described in detail in previous section.

    Screenshot shows the required permissions.

  3. Set the environment variables for the database name and container name, and finally select Deploy

    Screenshot shows the required variables to establish the connection with Azure Cosmos DB.

  4. Upon successful completion, the completion page would contain the link to the deployed app, or you go to the Vercel project's dashboard to get the link of your app. Now your app is successfully deployed to vercel.

Next steps