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:
- Ensure your static web app is on the Standard hosting plan: Private endpoints are only available for this plan.
- 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."
- Configure DNS settings: Ensure that the hostname of your static web app resolves to the private IP address of the private endpoint.
- 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."
- Configure DNS settings for CosmosDB: Ensure that the hostname of your CosmosDB instance resolves to the private IP address of the private endpoint.
- 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:
- Configure private endpoint in Azure Static Web Apps
- Quickstart: Create a private endpoint by using the Azure portal
- Enable Private access in Azure Cosmos DB for MongoDB vCore
- Configure Azure Private Link for an Azure Cosmos DB account
- Use private endpoints for access control By following these steps, your static web app will be able to access the CosmosDB instance securely through the private endpoint.
Please let us know if any further questions
Kindly accept if it helps
Thanks
Deepanshu