query a cosmosDB with private endpoint from a static webapp

De Bondt, Hannes (Mechelen) 65 Reputation points
2024-11-21T14:42:19.39+00:00

I have an application running in a static webapp. This application should be able to query a cosmosDB which is only reachable via a private endpoint.

What is the procedure to add a static webapp to a VNET to be able to reach the cosmosDB instance?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,694 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,006 questions
{count} votes

Accepted answer
  1. Deepanshukatara-6769 11,700 Reputation points
    2024-11-21T14:54:38.2733333+00:00

    Hello , Welcome to MS Q&A

    To query Azure Cosmos DB via a private endpoint from a web app, you need to set up a private endpoint for both the Cosmos DB and the web app. The private endpoint for the web app allows it to connect securely to the Cosmos DB over a private link, ensuring that the traffic does not traverse the public internet.

    To connect a static web app to a CosmosDB instance via a private endpoint, you need to follow these steps:

    1. Ensure your static web app is on the Standard hosting plan: Private endpoints are only available for this plan.
    2. Create a private endpoint for your static web app:
      • In the Azure portal, open your static web app.
      • Select the "Private Endpoints" option from the side menu and click "Add."
      • Fill in the required information, including the name, subscription, virtual network, and subnet.
      • Ensure that the option to integrate with a private DNS zone is set to "Yes."
    3. Configure DNS settings: Ensure that the hostname of your static web app resolves to the private IP address of the private endpoint.
    4. Create a private endpoint for your CosmosDB instance:
      • In the Azure portal, open your CosmosDB account.
      • Select the "Private Endpoint Connections" option from the side menu and click "Add."
      • Fill in the required information, including the name, subscription, virtual network, and subnet.
      • Ensure that the option to integrate with a private DNS zone is set to "Yes."
    5. Configure DNS settings for CosmosDB: Ensure that the hostname of your CosmosDB instance resolves to the private IP address of the private endpoint.
    6. Update your application configuration: Ensure that your application is configured to use the private IP addresses for both the static web app and CosmosDB instanc

    By following these steps, your static web app will be able to access the CosmosDB instance securely through the private endpoint.

    References:

    Please let us know if any further questions

    Kindly accept if it helps

    Thanks

    Deepanshu


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.